gpt4 book ai didi

ios - UILabel 背景颜色泄漏到边框

转载 作者:技术小花猫 更新时间:2023-10-29 10:17:30 25 4
gpt4 key购买 nike

我正在创建一个 UILabel,我使用以下代码为其设置背景颜色和圆角半径:

self.scoreLabel.backgroundColor = [UIColor DISRed];// custom red`
self.scoreLabel.layer.masksToBounds = YES;
self.scoreLabel.layer.cornerRadius = self.scoreLabel.frame.size.width/2;
self.scoreLabel.layer.borderWidth = 8.0;
self.scoreLabel.layer.borderColor = [[UIColor DISNavy] CGColor];

但是背景的颜色似乎漏到了边框的边缘(见图片)。任何想法为什么?知道如何解决吗?

enter image description here

最佳答案

我也遇到了同样的问题。这是一个愚蠢的错误。在 cornerRadius 的情况下,我总是忘记勾选 clipToBounds

所以,只需在 Storyboard 中勾选 UILabel 的 Clip to Bounds 即可解决我的问题。

是的,我们还需要保留以下代码:

label.layer.masksToBounds = true

关于ios - UILabel 背景颜色泄漏到边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29572461/

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