美文网首页
iOS开发笔记-66:swift4-UILabel设置内边距te

iOS开发笔记-66:swift4-UILabel设置内边距te

作者: 原味蛋炒饭 | 来源:发表于2017-12-13 10:14 被阅读107次
自己重写一个label
class JJLabel: UILabel {

    public var textInsets: UIEdgeInsets = .zero

    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    internal init(frame: CGRect, textInsets: UIEdgeInsets) {
        self.textInsets = textInsets
        super.init(frame: frame)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func drawText(in rect: CGRect) {
        super.drawText(in: UIEdgeInsetsInsetRect(rect, textInsets))
    }

}

使用:
beginTitle = JJLabel(frame: CGRect(x: 13, y: 114 + height!, width: 230, height: 44))
beginTitle?.attributedText = NSAttributedString(string: "开始日期   请选择开始日期", attributes: [NSAttributedStringKey.foregroundColor: kMainColor33, NSAttributedStringKey.font: FONT13])

beginTitle?.textInsets = UIEdgeInsets(top: 0, left: 13, bottom: 0, right: 13)

相关文章

网友评论

      本文标题:iOS开发笔记-66:swift4-UILabel设置内边距te

      本文链接:https://www.haomeiwen.com/subject/epcaixtx.html