这是我的子类:
class LabelWithBlackBackGround: UILabel {
var topInset = CGFloat(3)
var bottomInset = CGFloat(3)
var leftInset = CGFloat(15)
var rightInset = CGFloat(10)
override func drawText(in rect: CGRect) {
let insets: UIEdgeInsets = UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)
super.drawText(in: UIEdgeInsetsInsetRect(rect, insets))
}
override public var intrinsicContentSize: CGSize {
var intrinsicSuperViewContentSize = super.intrinsicContentSize
intrinsicSuperViewContentSize.height += topInset + bottomInset
intrinsicSuperViewContentSize.width += leftInset + rightInset
return intrinsicSuperViewContentSize
}
deinit {
}
}
问题是,当我有多行时,很多时候它会截断我的文本,就像这样:
可能是我的internalContentSize不正确,但是我找不到它出了什么问题。
当然,我尝试了那些:
label.numberOfLines = 0
label.lineBreakMode = .byWordWrapping