let label = UILabel(frame:CGRect(origin: .zero, size:CGSize(width:265, height:40)))
label.numberOfLines = 0
let attStr = NSMutableAttributedString(string: "xxxx")
let textAttach = NSTextAttachment()
textAttach.image = UIImage(named:"lottery_alert_warning")
textAttach.bounds = CGRect(origin: .zero, size:CGSize(width:14, height:14))
let font = UIFont.systemFont(ofSize:14)
let paddingTop = font.lineHeight-font.pointSize
textAttach.bounds = CGRect(x:0, y: -paddingTop, width: font.lineHeight, height: font.lineHeight)
let imageAtt = NSAttributedString(attachment: textAttach)
attStr.insert(imageAtt, at:0)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 2
paragraphStyle.alignment = .justified
let attrkey = [NSAttributedString.Key.font:font,
NSAttributedString.Key.foregroundColor:UIColor(hex:"333333"),
NSAttributedString.Key.paragraphStyle:paragraphStyle]
attStr.addAttributes(attrkey, range:NSRange(location:0, length: attStr.string.count))
label.attributedText = attStr
网友评论