我在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 label?.layer.cornerRadius = 5
函数中添加了awakeFromNib
。
它似乎没有影响标签。
答案 0 :(得分:6)
添加clipsToBounds属性:
label?.clipsToBounds = true // or use label?.layer.masksToBounds = true