Swift3 富文本 变更颜色 加删除线 字体大小 颜色 样式
//NSMutableAttributedString
func Add_lineoffset(rest:String,id :String, englishName :String, chineseName :String, isdelete :Bool) -> NSMutableAttributedString {
let attribute : NSMutableAttributedString = NSMutableAttributedString()
let currentPriceString : NSAttributedString = NSAttributedString(string: rest, attributes: [ NSAttributedStringKey.backgroundColor : UIColor.clear,NSAttributedStringKey.foregroundColor : REJEColor, NSAttributedStringKey.font : UIFont.systemFont(ofSize: 13.0)])
let oldPr: NSMutableAttributedString = NSMutableAttributedString(string: id, attributes: [NSAttributedStringKey.foregroundColor: REJEColor, NSAttributedStringKey.font : UIFont.boldSystemFont(ofSize: 15.0)])
let Engstr: NSMutableAttributedString = NSMutableAttributedString(string: englishName, attributes: [NSAttributedStringKey.foregroundColor : REJEColor, NSAttributedStringKey.font : UIFont.systemFont(ofSize: 15)])
let chinese: NSMutableAttributedString = NSMutableAttributedString(string: chineseName, attributes: [NSAttributedStringKey.foregroundColor : REJEColor, NSAttributedStringKey.font : UIFont.systemFont(ofSize: 15)])
if isdelete == true {//加删除线
oldPr.addAttribute(NSAttributedStringKey.strikethroughStyle, value: NSNumber.init(value: 1), range: NSRange(location: 0, length: oldPr.length))
Engstr.addAttribute(NSAttributedStringKey.strikethroughStyle, value: NSNumber(value: 1), range: NSMakeRange(0, Engstr.length))
chinese.addAttribute(NSAttributedStringKey.strikethroughStyle, value: NSNumber(value: 1), range: NSMakeRange(0, chineseName.count))
}
attribute.append(currentPriceString)
attribute.append(oldPr)
attribute.append(Engstr)
attribute.append(chinese)
return attribute
}
浙公网安备 33010602011771号