我正在继承 UIButton,我想要的是将按钮类型设置为 Round Rect。
按钮.h
@interface Button : UIButton {}
- (void)initialize;
@end
按钮.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 进行子类化,但事实上在 Developer's Docs 中没有提到不对其进行子类化。