Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use NSUnderlineStyle.PatternDot

I am trying to use NSMutableAttributedString with dotted underline below is my code but none of the Patterns seem to work am I missing something ?

var str : NSMutableAttributedString = NSMutableAttributedString(string: "HelloWorld")
        str.addAttribute(NSUnderlineStyleAttributeName  , value: NSNumber(integer:(NSUnderlineStyle.PatternDot).rawValue), range: NSMakeRange(0, str.length))
like image 391
Rajiv Patil Avatar asked Jan 20 '15 18:01

Rajiv Patil


1 Answers

You have to do it like this:

Xcode 10 • Swift 4.2 or later

yourLabel.attributedText = NSAttributedString(string: "Hello World !!!", attributes: [.underlineStyle: NSUnderlineStyle.patternDot.union(.single).rawValue])

Note: for older Swift syntax check edit history

like image 151
Leo Dabus Avatar answered Oct 14 '22 10:10

Leo Dabus