Last active
December 20, 2015 19:58
-
-
Save lludo/6186582 to your computer and use it in GitHub Desktop.
Create a custom view by loading it's content from a nib and provide a viewDidLoad like on the viewControllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface __class__ () | |
@property (nonatomic, strong) UIView *rootNibView; | |
@end | |
@implementation __class__ | |
- (id)initWithFrame:(CGRect)frame { | |
self = [super initWithFrame:frame]; | |
if (self) { | |
[self loadView]; | |
} | |
return self; | |
} | |
- (id)initWithCoder:(NSCoder *)aDecoder { | |
self = [super initWithCoder:aDecoder]; | |
if (self) { | |
[self loadView]; | |
} | |
return self; | |
} | |
- (void)loadView { | |
NSString *nibName = NSStringFromClass([self class]); | |
NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil]; | |
self.rootNibView = [nibViews objectAtIndex:0]; | |
self.rootNibView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | |
self.rootNibView.frame = self.bounds; | |
[self addSubview:self.rootNibView]; | |
[self viewDidLoad]; | |
} | |
- (void)viewDidLoad { | |
// Do any additional setup after loading the view from its nib. | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment