ios – 如何在Interface Builder中使用自定义UIButton?
发布时间:2020-12-14 17:56:45 所属栏目:百科 来源:网络整理
导读:我有一个子类UIButton加载一个Nib: @implementation BlaButtonVC- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { NSArray *subViews = [[NSBundle mainBundle] loadNibNamed:@"BlaButton" owner:self options:nil]; [
我有一个子类UIButton加载一个Nib:
@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,但按钮不会出现在Interface Builder中,也不会出现在Simulator中. 我错过了什么? 在这里您可以找到完整的样本: 解决方法
从StoryBoard初始化时,它调用方法initWithCoder:而不是initWithFrame:.除此之外,一切都是正确的.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |