繁体   English   中英

如何从UILabel的html链接中删除下划线?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM