Skip to content

Instantly share code, notes, and snippets.

@Ramshandilya
Created December 24, 2013 11:51
Show Gist options
  • Save Ramshandilya/8112211 to your computer and use it in GitHub Desktop.
Save Ramshandilya/8112211 to your computer and use it in GitHub Desktop.
A UIView category to load the view from XIB file
@interface UIView (LoadNib)
+ (id)loadInstanceFromNib;
+ (id)loadInstanceFromNibWithOwner:(id)owner;
@end
#import "UIView+LoadNib.h"
@implementation UIView (LoadNib)
+ (id)loadInstanceFromNib
{
UIView *result = nil;
NSArray *elements = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil];
for (id anObject in elements) {
if ([anObject isKindOfClass:[self class]]) {
result = anObject;
break;
}
}
return result;
}
+ (id)loadInstanceFromNibWithOwner:(id)owner
{
UIView *result = nil;
NSArray *elements = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:owner options:nil];
for (id anObject in elements) {
if ([anObject isKindOfClass:[self class]]) {
result = anObject;
break;
}
}
return result;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment