我创建了该类的子UIButton
类。我想在创建时更改其背景颜色。如何编写构造函数方法?
问问题
2531 次
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 回答