[英]How to remove underline from html link in UILabel?
let attrStr = try! NSMutableAttributedString(
data: courseList.breadcrumb.data(using: .unicode, allowLossyConversion: true)!,
options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil)
attrStr.addAttribute(NSForegroundColorAttributeName, value: UIColor.darkGray , range: NSRange(location: 0, length: attrStr.length))
descLbl.attributedText = attrStr
descLbl.linkAttributes = [
NSForegroundColorAttributeName: UIColor.darkGray,
NSUnderlineStyleAttributeName: NSNumber(value: false),
NSUnderlineColorAttributeName : UIColor.clear
]
上面是我的HTML編碼標簽代碼,我使用了TTTAttributedlabel
<a href=https://www.google.com>Subject Tutorials </a> > <a href=https://www.google.com>State Boards </a> > <a href=https://www.google.com>Madhya Pradesh State Board </a> > <a href=https://www.google.com>Hindi Medium </a> > <a href=https://www.google.com>Class 6 </a>
這是我必須編碼並顯示為無下划線且必須更改顏色的HTML。
將您的下划線屬性的值更改為以下內容:
NSUnderlineStyleAttributeName: NSUnderlineStyle.styleNone
您的屬性應如下所示:
descLbl.linkAttributes = [
NSForegroundColorAttributeName: UIColor.darkGray,
NSUnderlineStyleAttributeName: NSUnderlineStyle.styleNone,
NSUnderlineColorAttributeName : UIColor.clear
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.