let nsatrr = NSAttributedString.init(string:" " + (model.title ?? ""))
let string = NSMutableAttributedString.init(attributedString: nsatrr)
let font = UIFont.mediumSystemFont(ofSize: 14)
let textAttachment = NSTextAttachment()
textAttachment.image = UIImage.init(named: "Card_label_lto")
let paddingTop = font.lineHeight - font.pointSize
textAttachment.bounds = CGRect(x: 0, y: -paddingTop, width: 64, height: font.lineHeight)
let textAttachmentString = NSAttributedString(attachment: textAttachment)
string.insert(textAttachmentString, at: 0)
// 间距
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.minimumLineHeight = 20
paragraphStyle.maximumLineHeight = 20
string.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: string.length))
nameLabel.attributedText = string
富文本加图片 设置行高失效例子; 有效做法-label设置首行缩进 label上加imageview
最新推荐文章于 2023-09-07 11:03:15 发布