let uname:String = "abcdefg hijklmn opq rst uvw x"
let length = uname.lengthOfBytes(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
let leng = uname.characters.count(用这个)
print(length)
var myMutableString = NSMutableAttributedString()
myMutableString = NSMutableAttributedString(string: uname, attributes: [NSFontAttributeName:UIFont(name:"Georgia", size:14.0)!])
//添加不同字体颜色
myMutableString.addAttribute(NSForegroundColorAttributeName, value:UIColor.red, range:NSRange(location:1,length:4))
//添加不同字体大小
myMutableString.addAttribute(NSFontAttributeName, value:UIFont.systemFont(ofSize: 26.0), range:NSRange(location:1,length:4))
let lable = UILabel()
lable.frame = CGRect(x: 0, y: 60, width: 375, height: 40)
lable.backgroundColor = UIColor.lightGray
lable.attributedText = myMutableString
view.addSubview(lable)