Add NSUnderlineStyle.PatternDash to NSAttributedString in Swift?

前端 未结 4 706
佛祖请我去吃肉
佛祖请我去吃肉 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:35

    If you want an actual dashed line, you should OR | the raw values of both PatternDash and StyleSingle enums like below:

    let dashed     =  NSUnderlineStyle.PatternDash.rawValue | NSUnderlineStyle.StyleSingle.rawValue
    
    let attribs    = [NSUnderlineStyleAttributeName : dashed, NSUnderlineColorAttributeName : UIColor.whiteColor()];
    
    let attrString =  NSAttributedString(string: plainText, attributes: attribs)
    

提交回复
热议问题