gpt4 book ai didi

ios - 向 UILabel 添加填充

转载 作者:行者123 更新时间:2023-11-28 13:34:04 24 4
gpt4 key购买 nike

我想以编程方式向 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
}
}

最佳答案

使用插图怎么样?

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))
}
}

关于ios - 向 UILabel 添加填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56926327/

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