如何在 Swift 中创建标签点下划线

How to Create Label Doted Underline in Swift

我想在 Swift

中的标签上加点下划线

//你可以在swift 5

中添加这样的点下划线字符串
let string = NSMutableAttributedString(string: "Hello string")
                      string.addAttributes([.underlineStyle : NSUnderlineStyle.single.union(.patternDot).rawValue],
                                    range: NSRange(location: 0, length: string.length))
                   
yourLableName.attributedText = string

可以使用NSAttributedString在swift中设置下划线 5.

let string = NSAttributedString(string: "Receiver", attributes: [.underlineStyle: NSUnderlineStyle.single.union(.patternDash).rawValue])
label.attributedText = string