Last active
December 14, 2015 14:49
-
-
Save kharmabum/5103300 to your computer and use it in GitHub Desktop.
Generic custom UIView with nib file
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
// | |
// FTCustomUIViewWithNib.m | |
// OneHundredPlus | |
// | |
// Created by Juan-Carlos Foust on 06/03/2013. | |
// | |
#import "FTCustomUIViewWithNib.h" | |
@interface FTCustomUIViewWithNib () | |
@property (strong, nonatomic) IBOutlet UIView *containerView; | |
@end | |
@implementation FTCustomUIViewWithNib | |
//Set FileOwner in Nib to FTCustomUIViewWithNib | |
- (void)setup | |
{ | |
} | |
- (void)awakeFromNib | |
{ | |
[super awakeFromNib]; | |
[[[self class] nibCache] instantiateWithOwner:self options:nil]; | |
[self addSubview:self.containerView]; | |
[self setup]; | |
} | |
- (id)initWithFrame:(CGRect)frame | |
{ | |
self = [super initWithFrame:frame]; | |
if (self) | |
{ | |
[[[self class] nibCache] instantiateWithOwner:self options:nil]; | |
[self addSubview:self.containerView]; | |
[self setup]; | |
} | |
return self; | |
} | |
- (void) dealloc | |
{ | |
} | |
static UINib *_nib = nil; | |
+ (UINib *)nibCache | |
{ | |
if (!_nib) { | |
_nib = [UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil]; | |
} | |
return _nib; | |
} | |
+ (void)cacheNib | |
{ | |
_nib = [UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment