1

クラスのサブクラスを作成しましたUIButton。作成時に背景色を変更したい。コンストラクタメソッドはどのように記述すればよいですか?

4

1 に答える 1

0
-(id)initWithFrame :(CGRect)frame{
    if(self = [super init]) {

        // The default size for the save button is 49x30 pixels
        self.frame = frame;//CGRectMake(0, 0, 60.0, 34.0);

        // Center the text vertically and horizontally
        self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

        UIImage *image = [UIImage imageNamed:@"image.png"];






        [self setBackgroundImage:image forState:UIControlStateNormal];

            [self setBackgroundColor:[UIColor blueColor]];

        // Set the font properties
    //  [self setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];

        self.titleLabel.font = [UIFont boldSystemFontOfSize:12];


    }

    return self;
}
于 2012-09-27T08:32:01.150 に答える