Skip to content

Instantly share code, notes, and snippets.

@isaac-weisberg
Last active April 8, 2019 11:48
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 isaac-weisberg/9e4fc31101988a77bb784e0acbdf9332 to your computer and use it in GitHub Desktop.
Save isaac-weisberg/9e4fc31101988a77bb784e0acbdf9332 to your computer and use it in GitHub Desktop.
Load your views from xib
// XibbyView.h
@interface XibbyView : UIView
@property UIView* xibView;
@end
// XibbyView.m
@interface XibbyView ()
@property UIView* xibView;
@end
@implementation XibbyView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self renewXib];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self renewXib];
}
return self;
}
- (void)renewXib
{
if (self.xibView != nil) {
[self.xibView removeFromSuperview];
}
UIView* view = [[UINib nibWithNibName: NSStringFromClass([self class]) bundle:nil] instantiateWithOwner:self options:nil].firstObject;
view.frame = self.bounds;
[self addSubview:view];
self.xibView = view;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment