自定义返回NSMutableAttributedString
import UIKit
extension NSMutableAttributedString {
class func addAttributeLine(text:String, param:[NSAttributedString.Key : Any],lineColor: UIColor = UIColor.black,lineStyle:NSAttributedString.Key = NSAttributedString.Key.underlineStyle,isCover:Bool = false) -> (NSMutableAttributedString,NSMutableAttributedString) {
let array1:NSMutableDictionary = param as! NSMutableDictionary
let array2:NSMutableDictionary = param as! NSMutableDictionary
if param.keys.contains(NSAttributedString.Key.underlineStyle) {
array1.removeObject(forKey: NSAttributedString.Key.underlineStyle)
if isCover == true {
array2.setValue(lineStyle, forKey: NSAttributedString.Key.underlineStyle.rawValue)
}
}else{
array2.setValue(lineStyle, forKey: NSAttributedString.Key.underlineStyle.rawValue)
}
if param.keys.contains(NSAttributedString.Key.underlineColor) {
array1.removeObject(forKey: NSAttributedString.Key.underlineColor)
if isCover == true {
array2.setValue(lineColor, forKey: NSAttributedString.Key.foregroundColor.rawValue)
}
}else{
array2.setValue(lineColor, forKey: NSAttributedString.Key.foregroundColor.rawValue)
}
let attStr1 = NSMutableAttributedString.init(string: text, attributes: array1 as? [NSAttributedString.Key : Any])
let attStr2 = NSMutableAttributedString.init(string: text, attributes: (array2 as? [NSAttributedString.Key : Any]))
return (attStr1,attStr2)
}
}