Skip to content

Instantly share code, notes, and snippets.

@lludo
Last active December 20, 2015 19:58
Show Gist options
  • Save lludo/6186582 to your computer and use it in GitHub Desktop.
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
@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