最近由于开发需要,需要将Label的文字设置才如图样式
由于使用的swift开发,所以从网上搜索,大部分答案是这样的
let minuteString = String(15)
let secondString = String(54)
let hintString = NSMutableAttributedString(string: minuteString + "分" + secondString + "秒")
//获取要调整颜色的文字位置,调整颜色
let range1: NSRange = (hintString.string as NSString).range(of:minuteString)
hintString.addAttribute(kCTForegroundColorAttributeName as NSAttributedStringKey, value: UIColorFromRGB(rgbValue: 0xFF8617), range: range1)
let range2: NSRange = (hintString.string as NSString).range(of:secondString)
hintString.addAttribute(kCTForegroundColorAttributeName as NSAttributedStringKey, value: UIColorFromRGB(rgbValue: 0xFF8617),