Search code examples
objective-ciboutletiboutletcollection

Modify colors of buttons connected to a IBoutletCollection not working


I have this code should modify the colors of 24 buttons, connected to a IBoutletCollection :

In .h File:

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

In .m File:

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]);
    }

The IBOutletCollection's connected to the existing 24 buttons in my view, which is initially in gray color, when I run this function to modify the colors of the buttons they all go to the white color, how can I solve this?


Solution

  • use like this

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