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

  • 相关阅读:
    等待队列设备[置顶] Linux设备驱动,等待队列
    宠物功能[置顶] QQ宠物保姆
    选中拖动Unity3D系列教程–使用免费工具在Unity3D中开发2D游戏 第二节(下)
    序列化对象java中为什么要实现序列化,什么时候实现序列化?
    函数表达式[置顶] 母函数详解
    文件问题cocos2dx&cocosbuilder折腾记
    模块functionJavaScript学习笔记(二十五) 沙箱模式
    nullnullflume ng配置拓扑图
    对象序列化对象的序列化和反序列化
    扩展编程PHP自学之路PHP数据库编程
  • 原文地址:https://www.cnblogs.com/jukaiit/p/9110793.html
Copyright © 2011-2022 走看看