Pregunta

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

¿Fue útil?

Solución

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];
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top