gpt4 book ai didi

ios - 更改突出显示的 UIButton BG 颜色,但保留层角半径?

转载 作者:可可西里 更新时间:2023-11-01 03:38:08 24 4
gpt4 key购买 nike

我正在通过这个类别方法更改 UIButton 的背景颜色,使用 1px x 1px 图像:

- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state
{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(1, 1), NO, 0);
[backgroundColor setFill];
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, 1, 1));
UIImage *backgroundImage = UIGraphicsGetImageFromCurrentImageContext();
[self setBackgroundImage:backgroundImage forState:state];
UIGraphicsEndImageContext();
}

但是,这会覆盖我对 .layer.cornerRadius 的设置。我需要一个带圆角的按钮,但也需要一个我可以在突出显示时更改其背景颜色的按钮。

有什么办法解决这个问题吗?拐角半径需要是动态的。

最佳答案

因此,我所要做的就是确保 button.layer.masksToBounds 已打开。问题已解决,无需子类化。

关于ios - 更改突出显示的 UIButton BG 颜色,但保留层角半径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25769342/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com