我正在尝试使用带有虚线下划线的NSMutableAttributedString,下面是我的代码但是没有一个模式似乎工作我错过了什么?
var str : NSMutableAttributedString = NSMutableAttributedString(string: "HelloWorld")
str.addAttribute(NSUnderlineStyleAttributeName , value: NSNumber(integer:(NSUnderlineStyle.PatternDot).rawValue), range: NSMakeRange(0, str.length))
答案 0 :(得分:11)
你必须这样做:
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])