在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
let str = "富文本设置"
textView.isEditable = false self.view.addSubview(textView)
let amountString = NSMutableAttributedString(string:str) let s = NSString(string: str)//需要这一步。 let rang = s.range(of: s as String) amountString.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 13) ,range: rang) //行间距为5 let paragraphStye = NSMutableParagraphStyle() paragraphStye.lineSpacing = 5 amountString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStye, range: rang) for i in 0..<arrStr.count{ //与数组里相同的字符串,字体变大。也可改变颜色。 //指定range范围内的文本改变。 let newRange = s.range(of: arrStr[i] as String) amountString.addAttribute(NSForegroundColorAttributeName, value: UIColor.black, range: newRange) amountString.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 15) ,range: newRange) } textView.attributedText = amountString |
请发表评论