Add NSUnderlineStyle.PatternDash to NSAttributedString in Swift?

前端 未结 4 705
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-12 14:46

I\'m trying to add an underline to some text in my Swift app. This is the code I have currently:

let text = NSMutableAttributedString(string: self.currentHome.na         


        
4条回答
  •  猫巷女王i
    2021-02-12 15:37

    In Xcode 6.1, SDK iOS 8.1 toRaw() has been replaced by rawValue:

     text.addAttribute(NSUnderlineStyleAttributeName, value:  NSUnderlineStyle.StyleDouble.rawValue, range: NSMakeRange(0, text.length))
    

    Or Easier :

     var text : NSAttributedString = NSMutableAttributedString(string: str, attributes : [NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue]) 
    

提交回复
热议问题