我想创建一个自定义按钮,如果我不为该按钮设置任何颜色,这将帮助我将所有按钮背景颜色更改为默认红色。
所以我喜欢这一点,它在.h文件中运作良好我是否应该重写子类窗体父类(UIButton)中的属性
我
@interface ITSButton : UIButton
@property(nonatomic, strong) UIColor *backgroundColor;
@property(nonatomic, strong) UIColor *onPressBackgroundColor;
@end
在.M FIE
-(UIColor *)backgroundColor
{
if(!_backgroundColor){
_backgroundColor = [UIColor redColor];
}
return _backgroundColor;
}
但这里的问题backgroundColor
已经财产UIButton
类。如果我在ITSButton
中覆盖它,它是否好而清楚?
如果我不重写backgroundColor
财产,我不能使用功能(UIColor *)backgroundColor
,所以我不能设置默认背景为红色
我明白你的解决方案,所以我的问题的答案是“我不应该重写属性backgroundColor”吧? –
没错。由于初始化的方式,只需将按钮_be_设为红色即可。 – matt