Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kevvaere

macrumors newbie
Original poster
Jun 15, 2013
1
0
Hi everyone,

There is something i don't fully understand.
I am trying to make a class using UIButton as superclass. As such that i can use the functions made for UIButton and then i just add some of my own functions and variables. Here is some code of my custom class (Food):
Food.h
Code:
@interface Food : UIButton {
    double price;
    NSString *name;
    //IBOutlet UIButton *button;
}

Food.m
Code:
@implementation Food

- (id) initWithNameAndPrice:(NSString *) n price:(float) p {
    self = [super init];
    if (self) {
        [self setName:n];
        [self setPrice:p];
        [self setTitle:[NSString stringWithFormat:@"%@", name] forState:UIControlStateNormal];
        self.titleLabel.adjustsFontSizeToFitWidth = YES;
     }
    return self;
}

Now what i would like to do is to initialise the super (UIButton) with a given buttonType, like this;
Code:
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

Any idea how to do that? Is it possible? Because a [super init] makes a button with a custom type, which cannot be changed after it is set.

Thanks in advance.

Regards,
Kevin
 

Lapidus

macrumors regular
May 14, 2012
202
174
It's been a while. Have you found a solution?
Having the same question now..
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.