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

前端 未结 11 1296
终归单人心
终归单人心 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:03

    Swift 4.0 :

    Short and simple

     let LinkAttributes = NSMutableDictionary(dictionary: testLink.linkAttributes)
     LinkAttributes[NSAttributedStringKey.underlineStyle] =  NSNumber(value: false)
     LinkAttributes[NSAttributedStringKey.foregroundColor] = UIColor.black // Whatever your label color
     testLink.linkAttributes = LinkAttributes as NSDictionary as! [AnyHashable: Any]
    

提交回复
热议问题