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
Food.m
Now what i would like to do is to initialise the super (UIButton) with a given buttonType, like this;
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
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