问题
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))
回答1:
You have to do it like this:
yourLabel.attributedText = NSAttributedString(string: "Hello World !!!", attributes: [ NSUnderlineStyleAttributeName: NSUnderlineStyle.PatternDot.rawValue|NSUnderlineStyle.StyleSingle.rawValue])
Xcode 9 • Swift 4
yourLabel.attributedText = NSAttributedString(string: "Hello World !!!", attributes: [.underlineStyle: NSUnderlineStyle.patternDot.rawValue|NSUnderlineStyle.styleSingle.rawValue])
Xcode 10 • Swift 4.2
yourLabel.attributedText = NSAttributedString(string: "Hello World !!!", attributes: [.underlineStyle: NSUnderlineStyle.patternDot.union(.single).rawValue])
来源:https://stackoverflow.com/questions/28052823/how-to-use-nsunderlinestyle-patterndot