How to use NSUnderlineStyle.PatternDot

半腔热情 提交于 2020-01-05 02:35:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!