Created
January 7, 2015 15:39
-
-
Save loganwright/c457ca9067c332578815 to your computer and use it in GitHub Desktop.
UIView+NibInitable
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
#import <UIKit/UIKit.h> | |
@interface UIView (NibInitable) | |
- (instancetype)initWithNibNamed:(NSString *)nibNameOrNil; | |
@end |
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
#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