Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a custom UIButton with Interface Builder?

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];

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.

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.

What did I missed?

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

like image 255
gabor.orosz Avatar asked Dec 09 '12 09:12

gabor.orosz


1 Answers

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

like image 111
Martol1ni Avatar answered Sep 24 '22 10:09

Martol1ni