我正在对UIButton进行子类化,我想将按钮类型设置为Round Rect。
Button.h
@interface Button : UIButton {}
- (void)initialize;
@end
Button.m
的翻译是:Button.m
@implementation Button
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initialize];
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if(self){
[self initialize];
}
return self;
}
- (void)initialize
{
self.titleLabel.font = [UIFont systemFontOfSize:20];
self.titleLabel.textColor = [UIColor redColor];
self.titleLabel.textAlignment = UITextAlignmentCenter;
//[UIButton buttonWithType:UIButtonTypeRoundedRect];
}
@end
我尝试了 [UIButton buttonWithType:UIButtonTypeRoundedRect]
,但它不起作用。有人能建议如何使其起作用吗?
我知道在许多先前的帖子中已经说过不建议子类化 UIButton,但事实上在开发者文档中并没有提到不要子类化它。
#define BUTTON_FONT [UIFont fontWithName:aFontName size:aFontSize]
这样的常量怎么样? - Kai Huppmann