Add NSUnderlineStyle.PatternDash to NSAttributedString in Swift?

前端 未结 4 695
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  星月不相逢
    2021-02-12 15:32

    Turns out I needed the toRaw() method - this works:

    text.addAttribute(NSUnderlineStyleAttributeName, value: NSNumber(integer:(NSUnderlineStyle.StyleDouble).toRaw()), range: NSMakeRange(0, text.length))
    

提交回复
热议问题