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

标签 ios swift uilabel nsattributedstring

如何在 UILabel 中的内容的顶部和底部添加填充?

我试图通过 NSAttributedString 文本找到实现它的方法,但似乎无法找到仅将边距应用到顶部和底部的方法。

最佳答案

快速执行此操作:-

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

关于ios - 使用 Swift 将顶部和底部填充添加到 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32445229/

相关文章:

ios - 私有(private)协议(protocol)实现?

ios - 在静态 TableView 单元格中实现照片库

ios - viewcontroller 中的标签填充速度非常慢

ios - 如何为 UILabel 添加换行符?

ios - 如何实现iOS12.1版本自动布局约束的兼容性

ios - UIActionSheet 没有显示在 ios8 窗口中?

ios - 在 WatchKit 应用程序上连续显示来自 IOS 应用程序的心率

ios - 将 Realm Bool 数据分为 2 个部分 Tableview

ios - Swift - 如何获取当前时间(以秒为单位)?

swift - UILabel Swift/Storyboard 返回 nil