let errStr = "订课成功\r\n开课前2小时内不允许取消订课"
let strc = NSMutableAttributedString.init(string: errStr)
//间距
let paragraphStyle = NSMutableParagraphStyle.init()
paragraphStyle.lineSpacing = 10
paragraphStyle.alignment = .center
strc.addAttributes([NSAttributedStringKey.paragraphStyle : paragraphStyle], range: NSRange.init(location: 0, length: strc.length))
strc.addAttributes([NSAttributedStringKey.foregroundColor : UIColor.red], range: NSRange.init(location: 0, length: 4))
let str1M = NSAttributedString.init(string: "开课前2小时内不允许取消订课", attributes: [NSAttributedStringKey.foregroundColor:UIColor.yellow,NSAttributedStringKey.font:UIFont.systemFont(ofSize: 13)])
strc.replaceCharacters(in: NSRange.init(location: 6, length: 14), with: str1M)
最终得到的 strc 就是 一个可控各部分文字颜色 换行 对齐 的富文本