如何在Interface Builder中使用自定义UIButton? [英] How to use a custom UIButton with Interface Builder?

查看:74
本文介绍了如何在Interface Builder中使用自定义UIButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个子类UIButton加载一个Nib:

I have a subclass UIButton that loads a 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

我可以添加此按钮一个视图,像这样:

And I can add this button to a view, like this:

// 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子类而不是正常的子类。

My problem is I don't know how to do it from Interface Bulder, how to use this UIButton subclass instead of the normal one.

已将Button Type更改为Custom,将Custom Class更改为BlaButtonVC,但这还不够。它会调用BlaButtonVC initWithFrame,但按钮不会出现在Interface Builder中,也不会出现在模拟器中。

Already changed Button Type to Custom, and Custom Class to BlaButtonVC, but it's not enough. It'll call BlaButtonVC initWithFrame, but button will not appear nor in Interface Builder, nor in Simulator.

我错过了什么?

在这里您可以找到完整的样本:

https:// www .dropbox.com / s / ioucpb6jn6nr0hs / blabla1.zip

Here you can find the full sample:
https://www.dropbox.com/s/ioucpb6jn6nr0hs/blabla1.zip

推荐答案

StoryBoard ,它调用方法 initWithCoder:而不是 initWithFrame:。除此之外,一切都是正确的。

When initialized from the StoryBoard, it calls the method initWithCoder: instead of initWithFrame:. Aside from that, everything is correct.

这篇关于如何在Interface Builder中使用自定义UIButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆