我們在XIB裏拖一個控件,讓它繼承自定義類,並且初始化運行加載.m的文件
我在XIB拖一個UIVIEW控件 讓他繼承btnView,在btnView.m文件裏調用-(void)awakeFromNib
這樣 XIB初始化就會加載兩個Btn.......
@implementation btnView
-(void)awakeFromNib
{
_btnOne = [UIButton buttonWithType:UIButtonTypeRoundedRect];
_btnOne.frame = CGRectMake(10, 10, 200, 80);
[_btnOne setTitle:@"一號按鈕" forState:UIControlStateNormal];
[self addSubview:_btnOne];
_btnTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
_btnTwo.frame = CGRectMake(10, 200, 200, 80);
[_btnTwo setTitle:@"一號按鈕" forState:UIControlStateNormal];
[self addSubview:_btnTwo];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}