我有这个代码应该修改24个按钮的颜色,连接到IBoutlet集合:
In.h文件:
@property (nonatomic, strong) IBOutletCollection(UIButton) NSArray *buttons;
In.m文件:
for (UIButton *label in buttons) {
label.layer.borderWidth = 1.5f;
label.layer.borderColor = (__bridge CGColorRef)([UIColor colorWithRed:87.0/255.0 green:49.0/255.0 blue:42.0/255.0 alpha:1]);
label.layer.backgroundColor = (__bridge CGColorRef)([UIColor colorWithRed:134.0/255.0 green:98.0/255.0 blue:98.0/255.0 alpha:1]);
}
IBOutletCollection连接到我视图中现有的24个按钮,最初是灰色的,当我运行此功能修改按钮的颜色时,它们都变成了白色,我该如何解决这个问题?
像这样使用
[[myButton layer] setBorderWidth:2.0f];
[[myButton layer] setBorderColor:[UIColor colorWithRed:87.0/255.0 green:49.0/255.0 blue:42.0/255.0 alpha:1].CGColor];
[myButton setTitleColor:[UIColor colorWithRed:150.0/256.0 green:150.0/256.0 blue:150.0/256.0 alpha:1.0]]