Skip to content

Instantly share code, notes, and snippets.

@loganwright
Created January 7, 2015 15:39
Show Gist options
  • Save loganwright/c457ca9067c332578815 to your computer and use it in GitHub Desktop.
Save loganwright/c457ca9067c332578815 to your computer and use it in GitHub Desktop.
UIView+NibInitable
#import <UIKit/UIKit.h>
@interface UIView (NibInitable)
- (instancetype)initWithNibNamed:(NSString *)nibNameOrNil;
@end
#import "UIView+NibInitable.h"
@implementation UIView (NibInitable)
- (instancetype)initWithNibNamed:(NSString *)nibNameOrNil
{
if (!nibNameOrNil) {
nibNameOrNil = NSStringFromClass([self class]);
}
NSArray *viewsInNib = [[NSBundle mainBundle] loadNibNamed:nibNameOrNil
owner:self
options:nil];
for (id view in viewsInNib) {
if ([view isKindOfClass:[self class]]) {
self = view;
break;
}
}
return self;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment