Make link in UILabel.attributedText *not* blue and *not* underlined

前端 未结 11 1242
终归单人心
终归单人心 2020-12-24 05:18

I want some words within my OHAttributedLabel to be links, but I want them to be colors other than blue and I don\'t want the underline.

This is giving me a blue lin

11条回答
  •  天命终不由人
    2020-12-24 06:02

    For Swift 3 using TTTAttributedLabel

    let title: NSString = "Fork me on GitHub!"
    
    var attirutedDictionary = NSMutableDictionary(dictionary:attributedLabel.linkAttributes)
    
    attirutedDictionary[NSForegroundColorAttributeName] = UIColor.red
    attirutedDictionary[NSUnderlineStyleAttributeName] =  NSNumber(value: NSUnderlineStyle.styleNone.rawValue)
    
    attributedLabel.attributedText = NSAttributedString(string: title as String)
    attributedLabel.linkAttributes = attirutedDictionary as! [AnyHashable: Any]
    
    let range = subtitleTitle.range(of: "me")
    let url = URL(string: "http://github.com/mattt/")
    
    attributedLabel.addLink(to: url, with: range)
    

提交回复
热议问题