我想以编程方式向UILabel中的文本添加左填充。我一直在寻找解决方案,但是在现有的UILabel扩展中无法正常工作。
class TopSideHeaderLabel: UILabel {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
adjustsFontSizeToFitWidth = true
font = UIFont(name: Theme.PrimaryFontSemiBold, size: 16)
textColor = Theme.White
backgroundColor = Theme.background2
textAlignment = .left
}
}
答案 0 :(得分:1)
如何使用插图?
class TopSideHeaderLabel: UILabel {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
adjustsFontSizeToFitWidth = true
font = UIFont(name: Theme.PrimaryFontSemiBold, size: 16)
textColor = Theme.White
backgroundColor = Theme.background2
textAlignment = .left
}
override func drawText(in rect: CGRect) {
let insets = UIEdgeInsets.init(top: 10, left: 10, bottom: 10, right: 10)
super.drawText(in: UIEdgeInsetsInsetRect(rect, insets))
}
}