Last active
December 12, 2015 10:19
-
-
Save mattyohe/4758363 to your computer and use it in GitHub Desktop.
UIView Nib loading.
This file contains 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
// | |
// UIView+NibLoading.h | |
// | |
// Created by Matt Yohe on 2/11/13. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIView (NibLoading) | |
+(instancetype)loadInstanceFromNib; | |
@end |
This file contains 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
// | |
// UIView+NibLoading.m | |
// | |
// Created by Matt Yohe on 2/11/13. | |
// | |
#import "UIView+NibLoading.h" | |
@implementation UIView (NibLoading) | |
+(instancetype)loadInstanceFromNib | |
{ | |
UIView *result = nil; | |
NSArray *topLevelObjects = [[UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil] instantiateWithOwner:nil options:nil]; | |
for (id anObject in topLevelObjects) | |
{ | |
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