Related Documents
- Create a CustomView class inherit from UIView.(ex:CustomView.h & CustomView.m)
- Then create xib file with same name.(ex:CustomView.xib)
- Click the xib file
- Find the File's Owner and click it
- command + option + 3
- Input your Custom Class name.(ex:CustomView)
- Implement
initWithCoder
method
- (void) setup{
NSString *nibName = NSStringFromClass([self class]);
UINib *nib = [UINib nibWithNibName:nibName bundle:nil];
[nib instantiateWithOwner:self options:nil];
//Add the view loaded from the nib into self.
[self addSubview:self.view];
}
- (id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self) {
[self setup];
}
return self;
}
- If you want to input your parameter at storyboard.
- Drag a UIView to your storyboard.
- Click it -> command + option + 3 -> input your Custom Class name
- Find the "User denfined Runtime Attributes"
- enter the parameter you want
ex: String vTitle = "the title"
Key Path | Type | Value |
---|---|---|
vTitle | String | the title |
- Create a property in CustomView.h
@property (assign) NSString* vTitle;
- Implement
awakeFromNib
in CustomView.m
- (void)awakeFromNib {
labelTitle.text = vTitle;
}