Last active
November 19, 2015 18:01
-
-
Save meech-ward/4b94841d8f81d3d01a4f to your computer and use it in GitHub Desktop.
Add a UIView with a 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
@interface XIBView() | |
/// The main view in the xib file. | |
@property (strong, nonatomic) IBOutlet UIView *contianerView; | |
@end | |
@implementation XIBView | |
#pragma mark - SetUp | |
- (instancetype)initWithFrame:(CGRect)frame { | |
self = [super initWithFrame:frame]; | |
if (self) { | |
[self setUp]; | |
} | |
return self; | |
} | |
- (instancetype)initWithCoder:(NSCoder *)aDecoder { | |
self = [super initWithCoder:aDecoder]; | |
if (self) { | |
[self setUp]; | |
} | |
return self; | |
} | |
- (void)setUp { | |
[self xibSetUp]; | |
[self viewSetUp]; | |
} | |
- (void)xibSetUp { | |
// Add the xib view to this view | |
[[NSBundle mainBundle] loadNibNamed:@"XIBView" owner:self options:nil]; | |
// Make the view stretch with containing view | |
_contianerView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); | |
// Add the container to the current view | |
[self addSubview: self.contianerView]; | |
_contianerView.frame = self.bounds; | |
} | |
- (void)viewSetUp { | |
self.layer.cornerRadius = 4.0; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment