我想画像画一样的下划线。但是"NSUnderlineStyleAttributeName“不起作用,请帮我
发布于 2022-05-10 06:24:14
您可以使用NSAttributedString来完成这个任务。
例子:
let underlineAttribute = [NSAttributedString.Key.underlineStyle: NSUnderlineStyle.thick.rawValue]
let underlineAttributedString = NSAttributedString(string: "StringWithUnderLine", attributes: underlineAttribute)
YourLabel.attributedText = underlineAttributedString扩展
extension UILabel {
func underline() {
if let textString = self.text {
let attributedString = NSMutableAttributedString(string: textString)
attributedString.addAttribute(NSAttributedString.Key.underlineStyle,
value: NSUnderlineStyle.single.rawValue,
range: NSRange(location: 0, length: attributedString.length))
attributedText = attributedString
}
}
}https://stackoverflow.com/questions/72180767
复制相似问题