• 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

  • 相关阅读:
    CentOS Linux 7 安装教程
    计算机网络概念
    计算机操作系统概念简介
    基础-计算机及操作系统和应用程序的概念
    Spring mvc注解说明
    kaptcha Spring 整合
    Spring常用注解
    Spring bean的自动装配属性
    HQL(Hibernate Query language)语言
    JDBC、Hibernate、Java类型对照表
  • 原文地址:https://www.cnblogs.com/jukaiit/p/9110793.html
Copyright © 2020-2023  润新知