Как удалить подчеркивание из ссылки html в UILabel? - PullRequest
0 голосов
/ 05 июля 2018
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-код, который я должен кодировать и показывать без подчеркивания и должен изменить цвет.

1 Ответ

0 голосов
/ 05 июля 2018

Измените значение атрибута подчеркивания на следующее:

NSUnderlineStyleAttributeName: NSUnderlineStyle.styleNone

Ваши атрибуты должны выглядеть следующим образом:

descLbl.linkAttributes = [
    NSForegroundColorAttributeName: UIColor.darkGray,
    NSUnderlineStyleAttributeName: NSUnderlineStyle.styleNone,
    NSUnderlineColorAttributeName : UIColor.clear
]
...