簡體   English   中英

將填充添加到UILabel

[英]Add Padding to UILabel

我想以編程方式將左填充添加到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))
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM