UIButton自定义边框中的Tintcolor [英] Tintcolor in custom border of UIButton

查看:166
本文介绍了UIButton自定义边框中的Tintcolor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为圆形自定义边框创建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];
}

问题是当自定义边框出现弹出时不具有相同的行为使用tintColor的另一个控件:

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

我该如何处理?

非常感谢

推荐答案

实施 tintColorDidChange 。 iOS将按钮的tintColor更改为灰色,但图层的borderColor仍然是旧的蓝色。你必须自己更改borderColor,iOS无法知道边框应该像你的色调一样着色。

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

使用 setNeedsDisplay 系统将调用 drawRect:,它应该更新图层颜色。

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

你也可以使用它:

- (void)tintColorDidChange {
    [super tintColorDidChange];
    [[self layer] setBorderColor:self.tintColor.CGColor];
}

这篇关于UIButton自定义边框中的Tintcolor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆