• swift 富文本设置


    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

  • 相关阅读:
    PAT 2016 数据的交换输出
    HDU 2020 绝对值排序
    HDU 2013 蟠桃记
    HDU 2005 第几天?
    HDU 2004 成绩转换
    系统时钟初始化
    array_map 去除数组参数里面左右两端空格
    建立自己的异常类方式
    laravel withCount 统计关联数量
    laravel门面和服务提供者使用
  • 原文地址:https://www.cnblogs.com/linximu/p/7048471.html
Copyright © 2020-2023  润新知