Skip to content

Instantly share code, notes, and snippets.

@kharmabum
Last active December 14, 2015 14:49
Show Gist options
  • Save kharmabum/5103300 to your computer and use it in GitHub Desktop.
Save kharmabum/5103300 to your computer and use it in GitHub Desktop.
Generic custom UIView with nib file
//
// 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