自己重写一个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)
网友评论