我有一个UIButton我在IB中添加的,但是这个按钮后面的视图会改变颜色,我需要在InfoDark和InfoLight之间切换按钮的类型.但奇怪的是,buttonType财产是只读的.那么如何在明暗信息按钮之间切换?
我是UIButton的子类,我想要的是将按钮类型设置为Round Rect.
Button.h
@interface Button : UIButton {}
- (void)initialize;
@end
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
在这里我尝试[UIButton buttonWithType:UIButtonTypeRoundedRect]但它不起作用.任何人都可以建议如何使其工作?
我在之前的许多文章中都知道,不推荐使用Subclassing UIButton,但事实上在Developer's Docs中没有提及NOT子类化它.
我有一个用IB制作的UIButton,它设置为"Rounded Rect".有一次,我想在代码中将类型更改为"自定义",这可能吗?我看到类型可以在创建时设置,但是没有看到以后是否可以更改它.