我在objective-c项目中使用IBInspectables。我不想为这些设置一些默认值。这并不是一个简单的设置默认值,就像在swift中一样,所以我试图在init方法中这样做:
@interface PushButtonView ()
@property (nonatomic, strong) IBInspectable UIColor *fillColor;
@property IBInspectable BOOL isAddButton;
@end
@implementation PushButtonView
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if(self){
self.fillColor = [UIColor blueColor];
self.isAddButton = YES;
}
return self;
}
这允许我根据需要更改接口生成器中的值。但是,如果我选择default作为按钮的fillColor,它在界面生成器中显示为黑色,而不是蓝色。你知道我在这里做错了什么吗?任何指针都会很棒。
您不能更改默认颜色。因为UIButton
上的这个颜色是黑色。你的按钮确实会显示为黑色。