[英]Corner radius in custom UILabel class
I have a label in my Storyboard where i subclass a custom class with the following code 我在情节提要中有一个标签,在其中我使用以下代码对自定义类进行子类化
@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
}
}
I've added label?.layer.cornerRadius = 5
in my custom TableviewCell awakeFromNib
function. 我在自定义TableviewCell
awakeFromNib
函数中添加了label?.layer.cornerRadius = 5
。
It doesn't seem to be affecting the label. 它似乎并没有影响标签。
添加clipsToBounds属性:
label?.clipsToBounds = true // or use label?.layer.masksToBounds = true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.