自己重写一个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设置内边距textInsets
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 问题说明 默认Label的显示效果如下 很多情况下,需要如下有内边距的效果(注意第一行与最后一行文字与label的...