zoukankan      html  css  js  c++  java
  • Swift NSAttributedString的使用

     

    NSMutableAttributedString

     

     

      

     

     

     

         let testAttributes = [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.backgroundColor: UIColor.yellow,NSAttributedStringKey.strikethroughStyle:1] as [NSAttributedStringKey : Any]

            

            let testAttributeString = NSAttributedString(string: "富文本测试", attributes:testAttributes)

            

            self.testLabel.attributedText = testAttributeString

            

            

            let prefix = "¥" + "100"

            let suffix = "¥" + "200"

            

            let string = prefix + suffix

            let myAttribute = [NSAttributedStringKey.foregroundColor: UIColor.lightGray,

                               NSAttributedStringKey.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue,

                               NSAttributedStringKey.font: UIFont.systemFont(ofSize: 13)] as [NSAttributedStringKey : Any]

            

            let redAttribute = [NSAttributedStringKey.foregroundColor: UIColor.red,

                                NSAttributedStringKey.font: UIFont.systemFont(ofSize: 15)] as [NSAttributedStringKey : Any]

            

            let attString = NSMutableAttributedString(string: string)

            attString.addAttributes(redAttribute, range:NSRange.init(location: 0, length: prefix.count))

            attString.addAttributes(myAttribute, range: NSRange.init(location: prefix.count, length: suffix.count))

            self.titleLabel.attributedText = attString

  • 相关阅读:
    IT北漂攻略—择业篇(程序员.net)
    Log4net和Log2Console 结合使用时出现的中文问题
    日志设计规范
    IT北漂攻略租房篇
    Log2Console日志监测工具使用方法
    一些好用的开源控件
    工作流设计简介
    代码设计规范
    正则表达式分割字符串但是不分割字符串中引号中间的数据
    解决Android 应用运行报Unable to resolve superclass of L错误
  • 原文地址:https://www.cnblogs.com/jukaiit/p/9110793.html
Copyright © 2011-2022 走看看