想添加NSMutableAttributedString
NSMutableParagraphStyle
和firstLineHeadIndent
的左边距,但没有运气,firstLineHeadIndent
或headIndent
无效
我的实现:
lazy var priseField: UILabel = {
let label = UILabel()
label.font = UIFont.boldSystemFont(ofSize: 15)
label.textColor = .black
let string = self.addMutableAttribute(string: "50")
string.append(self.addAttribute(string: "lari"))
label.attributedText = string
return label
}()
func addMutableAttribute(string:String = "") -> NSMutableAttributedString {
let attribute:[NSAttributedString.Key : Any] = [ NSAttributedString.Key.foregroundColor: UIColor.black,
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)]
let attrString = NSMutableAttributedString(string: string, attributes: attribute)
return attrString
}
func addAttribute(string:String = "") -> NSMutableAttributedString {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.firstLineHeadIndent = 3;
paragraphStyle.headIndent = 3
let attribute:[NSAttributedString.Key : Any] = [
.foregroundColor: UIColor.darkGray,
.paragraphStyle: paragraphStyle,
.font: UIFont.boldSystemFont(ofSize: 12),
.baselineOffset: 1
]
let attrString = NSMutableAttributedString(string: string, attributes: attribute)
return attrString
}
结果是:
我想增加50到拉里之间的距离