Created
January 22, 2012 12:40
-
-
Save DavidBarry/1656949 to your computer and use it in GitHub Desktop.
This is a subclass of UIView to reduce boilerplate code when using Interface Builder to layout a custom UIView subclass.
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
#import <UIKit/UIKit.h> | |
@interface SDViewWithNibLayout : UIView | |
+ (id)viewFromNib; | |
+ (NSString *)nibName; | |
@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
#import "SDViewWithNibLayout.h" | |
@implementation SDViewWithNibLayout | |
+ (id)viewFromNib { | |
UINib *nib = [UINib nibWithNibName:[self nibName] bundle:[NSBundle mainBundle]]; | |
NSArray *nibArray = [nib instantiateWithOwner:nil options:nil]; | |
id view = nil; | |
for (id object in nibArray) { | |
if ([object isKindOfClass:[self class]]) { | |
view = object; | |
break; | |
} | |
} | |
return view; | |
} | |
+ (NSString *)nibName { | |
return NSStringFromClass([self class]); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment