Raj*_*til 2 iphone nsattributedstring ios ios7 swift
我试图使用NSMutableAttributedString与下面的虚线下划线是我的代码,但没有一个模式似乎工作,我错过了什么?
var str : NSMutableAttributedString = NSMutableAttributedString(string: "HelloWorld")
str.addAttribute(NSUnderlineStyleAttributeName , value: NSNumber(integer:(NSUnderlineStyle.PatternDot).rawValue), range: NSMakeRange(0, str.length))
Run Code Online (Sandbox Code Playgroud)
Leo*_*bus 12
你必须这样做:
yourLabel.attributedText = NSAttributedString(string: "Hello World !!!", attributes: [ NSUnderlineStyleAttributeName: NSUnderlineStyle.PatternDot.rawValue|NSUnderlineStyle.StyleSingle.rawValue])
Run Code Online (Sandbox Code Playgroud)
Xcode 9•Swift 4
yourLabel.attributedText = NSAttributedString(string: "Hello World !!!", attributes: [.underlineStyle: NSUnderlineStyle.patternDot.rawValue|NSUnderlineStyle.styleSingle.rawValue])
Run Code Online (Sandbox Code Playgroud)
Xcode 10•Swift 4.2
yourLabel.attributedText = NSAttributedString(string: "Hello World !!!", attributes: [.underlineStyle: NSUnderlineStyle.patternDot.union(.single).rawValue])
Run Code Online (Sandbox Code Playgroud)