gpt4 book ai didi

ios - 自定义 UILabel 类中的圆角半径

转载 作者:搜寻专家 更新时间:2023-11-01 05:56:10 25 4
gpt4 key购买 nike

我的 Storyboard 中有一个标签,我在其中使用以下代码对自定义类进行子类化

@IBDesignable class PaddingLabel: UILabel {

@IBInspectable var topInset: CGFloat = 5.0
@IBInspectable var bottomInset: CGFloat = 5.0
@IBInspectable var leftInset: CGFloat = 7.0
@IBInspectable var rightInset: CGFloat = 7.0

override func drawText(in rect: CGRect) {
let insets = UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)
super.drawText(in: UIEdgeInsetsInsetRect(rect, insets))
}

override var intrinsicContentSize: CGSize {
var intrinsicSuperViewContentSize = super.intrinsicContentSize
intrinsicSuperViewContentSize.height += topInset + bottomInset
intrinsicSuperViewContentSize.width += leftInset + rightInset
return intrinsicSuperViewContentSize
}
}

我在我的自定义 TableviewCell awakeFromNib 函数中添加了 label?.layer.cornerRadius = 5

它似乎没有影响标签。

最佳答案

添加 clipsToBounds 属性:

label?.clipsToBounds = true // or use label?.layer.masksToBounds = true

关于ios - 自定义 UILabel 类中的圆角半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43490681/

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