我为圆形自定义边框创建了 UIButton 的子类:
- (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 的控件的行为不一样:
我该如何处理?
非常感谢
实施tintColorDidChange https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/tintColorDidChange在你的 UIButton 子类中。 iOS 将按钮的tintColor 更改为灰色,但图层的borderColor 仍然是旧的蓝色。你必须自己改变 borderColor,iOS 不可能知道边框的颜色应该像你的色调一样。
- (void)tintColorDidChange {
[super tintColorDidChange];
[self setNeedsDisplay];
}
当你使用后setNeedsDisplay
系统会调用drawRect:
,这应该更新图层颜色。
你或许也可以使用这个:
- (void)tintColorDidChange {
[super tintColorDidChange];
[[self layer] setBorderColor:self.tintColor.CGColor];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)