Created
May 21, 2015 19:41
-
-
Save sdgandhi/b3e3d738beb47f6b0476 to your computer and use it in GitHub Desktop.
Setting up UIView subclass from XIB
This file contains hidden or 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
@property (nonatomic, strong) UIView *view; | |
- (instancetype)initWithFrame:(CGRect)frame | |
{ | |
self = [super initWithFrame:frame]; | |
if (self) { | |
[self setupViewFromNib]; | |
[self setupUI]; | |
} | |
return self; | |
} | |
- (id)initWithCoder:(NSCoder *)aDecoder | |
{ | |
self = [super initWithCoder:aDecoder]; | |
if (self) { | |
[self setupViewFromNib]; | |
[self setupUI]; | |
} | |
return self; | |
} | |
- (void)setupViewFromNib | |
{ | |
NSBundle *bundle = [NSBundle bundleForClass:self.class]; | |
UINib *nib = [UINib nibWithNibName:NSStringFromClass(self.class) bundle:bundle]; | |
_view = [nib instantiateWithOwner:self options:nil].firstObject; | |
_view.frame = self.bounds; | |
_view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
[self addSubview:_view]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment