let titleLabe = UILabel()
titleLabe.frame = CGRect(x: 0, y: 0, width: frame.size.width, height: 50)
let testStr = "天天涨停板,哈哈"
let attributeStr = NSMutableAttributedString(string: testStr)
attributeStr.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.red, range: NSMakeRange(0, 6))
attributeStr.addAttribute(NSAttributedString.Key.font, value: UIFont.systemFont(ofSize: 18), range: NSMakeRange(0, 6))
attributeStr.addAttribute(NSAttributedString.Key.font, value: UIFont.systemFont(ofSize: 12), range: NSMakeRange(testStr.count - 3, 3))
attributeStr.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.yellow, range: NSMakeRange(testStr.count - 3, 3))
let attach = NSTextAttachment()
attach.image = UIImage(named: "icon.jpg")
attach.bounds = CGRect(x: 0, y: 0, width: 40, height: 40)
let attachStr = NSAttributedString(attachment: attach)
attributeStr.insert(attachStr, at: 5)
titleLabe.attributedText = attributeStr
addSubview(titleLabe)