iPad Superclass UIButton

Discussion in 'iOS 6' started by Kevvaere, Jun 15, 2013.

  1. Kevvaere macrumors newbie

    Joined:
    Jun 15, 2013
    #1
    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
     
  2. Lapidus macrumors regular

    Lapidus

    Joined:
    May 14, 2012
    #2
    It's been a while. Have you found a solution?
    Having the same question now..
     

Share This Page