Skip to content

Instantly share code, notes, and snippets.

@troystribling
Created May 5, 2012 16:47
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 troystribling/2603949 to your computer and use it in GitHub Desktop.
Save troystribling/2603949 to your computer and use it in GitHub Desktop.
Load UIView from NIB
#import "NSObject+Extensions.h"
@interface UIView (Extensions)
+ (UIView*)loadView:(Class)_viewClass;
@end
@implementation UIView (Extensions)
+ (UIView*)loadView:(Class)_viewClass {
NSString* nibName = [_viewClass className];
UIView* view = nil;
NSArray* nibContents = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil];
NSEnumerator *nibEnumerator = [nibContents objectEnumerator];
NSObject* nibItem = nil;
while ((nibItem = [nibEnumerator nextObject]) != nil) {
if ([nibItem isKindOfClass:_viewClass]) {
view = (UIView*)nibItem;
break;
}
}
return view;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment