Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tintcolor in custom border of UIButton

I make a subclass of UIButton for rounded custom border:

- (void)drawRect:(CGRect)rect
{
    [[self layer] setCornerRadius:CORNER_RADIUS];
    [[self layer] setMasksToBounds:YES];   
    [[self layer] setBorderWidth:1];
    [[self layer] setBorderColor:self.tintColor.CGColor];
    [self.imageView setTintColor:self.tintColor];
}

The issue is when appear a popover the custom border not has the same behavior of the other control with tintColor:

enter image description here

enter image description here

How can i handle it?

Many thanks

like image 704
fabrizotus Avatar asked Jan 17 '14 17:01

fabrizotus


1 Answers

Implement tintColorDidChange in your UIButton subclass. iOS changes the tintColor of your button to gray, but borderColor of the layer is still the old blue color. You have to change borderColor yourself, there is no way that iOS knows that the border should be colored like your tint.

- (void)tintColorDidChange {
    [super tintColorDidChange];
    [self setNeedsDisplay];
}

After you used setNeedsDisplay the system will call drawRect:, which should update the layer color.

You could probably use this as well:

- (void)tintColorDidChange {
    [super tintColorDidChange];
    [[self layer] setBorderColor:self.tintColor.CGColor];
}
like image 149
Matthias Bauch Avatar answered Sep 29 '22 06:09

Matthias Bauch