How to change button borderColor in UICollectionReusableView when cell alloced

222 views Asked by At

I have a UICollectionReusableView with buttons, when user taps on buttons I would like to change backgroundColor and borderColor. BackgroundColor changed but borderColor did not change.
Code:

@implementation ClothesTopView

//==============================================================================

- (void)configCell:(id<ClothesTopViewDelegate>)delegate
{
    _clothesTopViewDelegate = delegate;
    for (UIButton *button in _topButtonCollection)
    {
        button.layer.cornerRadius = 2;
        button.layer.borderWidth = 1.f;
        button.layer.borderColor = [UIColor whiteColor].CGColor;
    }
}

//==============================================================================

- (IBAction)topButtonAction:(UIButton *)sender
{
    for (UIButton *button in _topButtonCollection)
    {
        if (button == sender)
        {
            sender.layer.borderColor = [UIColor colorWithRed:226/255.f green:71/255.f blue:49/255.f alpha:1.f].CGColor;
            sender.backgroundColor = [UIColor colorWithRed:226/255.f green:71/255.f blue:49/255.f alpha:1.f];
        }
        else
        {
            button.layer.borderColor = [UIColor whiteColor].CGColor;
            button.backgroundColor = [UIColor clearColor];
        }
    }
    [_clothesTopViewDelegate topViewButtonDidPressWithTitle:sender.titleLabel.text];
}

//=========================================================================

@end
1

There are 1 answers

0
zurakach On BEST ANSWER

After applying changes try to call this method

 [self setNeedsDisplay];

This will tell iOS to redraw cell and you border colors should change.