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

  • 相关阅读:
    [转]iOS多线程编程之NSThread的使用
    IOS 本地通知
    IOS 使用程序外地图(IOS Map and google Map)
    syq小姐姐的分享的历年考试经验
    对拍——我认为的最简写法
    对拍——我目前可以找到的最简写法
    数论板子——来自Loi_black
    一些神奇的(优化)板子——来自Loi_black的博客
    马拉车——模版+KMP——模版
    国庆七天乐——第七天
  • 原文地址:https://www.cnblogs.com/jukaiit/p/9110793.html
Copyright © 2011-2022 走看看