Skip to content

Instantly share code, notes, and snippets.

@meech-ward
Last active November 19, 2015 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meech-ward/4b94841d8f81d3d01a4f to your computer and use it in GitHub Desktop.
Save meech-ward/4b94841d8f81d3d01a4f to your computer and use it in GitHub Desktop.
Add a UIView with a XIB
@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