修改连接到IBoutletCollection的按钮的颜色不起作用

时间:2014-10-18 12:59:34

标签: objective-c iboutlet iboutletcollection

我有这个代码应该修改24个按钮的颜色,连接到IBoutletCollection:

在.h文件中:

@property (nonatomic, strong) IBOutletCollection(UIButton) NSArray *buttons;

在.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个按钮,最初为灰色,当我运行此功能修改按钮的颜色时,它们都变为白色,我该如何解决?

1 个答案:

答案 0 :(得分:0)

像这样使用

 [[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]]