简体   繁体   English

使用Swift将顶部和底部填充添加到UILabel

[英]Add top and bottom padding to UILabel using Swift

How do you add padding to the top and bottom of the content within a UILabel ? 如何在UILabel内容的顶部和底部添加填充?

I have tried to find the means of doing it via NSAttributedString text but cannot seem to find a way to apply margins to the top and bottom only. 我试图找到通过NSAttributedString文本执行此操作的方法,但似乎找不到找到仅将边距应用于顶部和底部的方法。

Do this in swift :- 迅速做到这一点:-

class Label: UILabel {
    override func drawTextInRect(rect: CGRect) {
        super.drawTextInRect(UIEdgeInsetsInsetRect(rect, UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)))
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM