示例文本影像
我想像圖片一樣畫下劃線。但“NSUnderlineStyleAttributeName”不起作用請幫幫我
uj5u.com熱心網友回復:
您可以使用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://www.uj5u.com/qianduan/493617.html
