Nib をロードするサブクラス UIButton があります。
@implementation BlaButtonVC
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSArray *subViews = [[NSBundle mainBundle] loadNibNamed:@"BlaButton" owner:self options:nil];
[self addSubview:subViews[0]];
}
return self;
}
@end
そして、このボタンを次のようにビューに追加できます。
// ViewController.m
BlaButtonVC *button = [[BlaButtonVC alloc] initWithFrame:CGRectMake(10, 10, 280, 44)];
button.titleXLabel.text = @"Nyuff";
button.descLabel.text = @"Kukk";
[self.view addSubview:button];
私の問題は、Interface Bulder からそれを行う方法、通常の代わりにこの UIButton サブクラスを使用する方法がわからないことです。
Button Type を Custom に、Custom Class を BlaButtonVC に変更しましたが、まだ十分ではありません。BlaButtonVC initWithFrame を呼び出しますが、ボタンはインターフェイス ビルダーにもシミュレーターにも表示されません。
私は何を逃したのですか?
ここで完全なサンプルを見つけることができます:
https://www.dropbox.com/s/ioucpb6jn6nr0hs/blabla1.zip