我正在使用TTTAttributedLabel (https://github.com/twotoasters/TTTAttributedLabel)。我已经正确获取了带有一些可点击文本的标签。我需要像上面图片中的用户名那样显示我的文本(即没有下划线)。我该怎么做?
NSDictionary *linkAttributes = @{[NSNumber numberWithInt:kCTUnderlineStyleNone] : (id)kCTUnderlineStyleAttributeName};
self.label.linkAttributes = linkAttributes;
如果您已经具有带下划线样式的标签,且要以编程方式删除它,请使用以下代码
let string = "your text"
let attributes: [NSAttributedString.Key: Any] = [
.font: UIFont.systemFont(ofSize: 13)
]
let attributedString = NSAttributedString(string: string,
attributes: attributes)
yourLabel.attributedText = attributedString
对于 Swift 4.0
let LinkAttributes = NSMutableDictionary(dictionary: testLink.linkAttributes)
LinkAttributes[NSAttributedStringKey.underlineStyle] = NSNumber(value: false)
yourLabel.linkAttributes = LinkAttributes as NSDictionary as! [AnyHashable: Any]