我正在尝试以编程方式将链接添加到UILabel的最后一部分,但没有使整个UILabel成为链接(当我更改输入字符串时,请忽略范围)。
let mutableString = NSMutableAttributedString(string: "This is a string. This is the link that should be underlined")
mutableString.addAttribute(NSLinkAttributeName, value: "www.website.com", range: NSMakeRange(57, 16))
self.label.attributedText = mutableString
上面的代码在功能上实现了我想要的功能,但是现在该链接带有下划线了,这不是我想要的。因此,我添加了以下行:
mutableString.addAttribute(NSUnderlineColorAttributeName, value: NSUnderlineStyle.StyleNone.rawValue, range: NSMakeRange(57, 16))
现在,范围内的文本将根本不会出现。关于如何使这项工作有任何想法吗?
试试这个
let mutableString = NSMutableAttributedString(string: "This is a string. This is the link that should be underlined")
mutableString.addAttribute(NSLinkAttributeName, value: "www.website.com", range: NSMakeRange(0, 16))
mutableString.addAttribute(NSUnderlineStyleAttributeName, value: NSUnderlineStyle.StyleNone.rawValue, range: NSMakeRange(0, 16))
mutableString.addAttribute(NSUnderlineColorAttributeName, value: UIColor.clearColor(), range: NSMakeRange(0, 16))
希望对您有所帮助,因为我的魅力十足
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句