我有UITextView
,并想在其中添加部分文本链接。这些嵌入的链接应带有下划线。当我将其font
设置为内置文件之一时,它可以正常工作,但可以Ubuntu font
即使设置了超链接颜色也不起作用。
let linkTextView = UITextView()
let linkAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: Design.colorPrimary,
NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue,]
linkTextView.linkTextAttributes = linkAttributes
linkTextView.isUserInteractionEnabled = false
let allText = "example link"
let linkText = "link"
let NStext = NSString(string: allText)
let attributedString = NSMutableAttributedString(string: allText)
attributedString.addAttribute(.link, value: NSURL(string: "https://www.apple.com")!, range: NStext.range(of: linkText))
linkTextView.attributedText = attributedString
linkTextView.heightAnchor.constraint(equalToConstant: 100).isActive = true
linkTextView.font = UIFont(name: "Ubuntu", size: 20)!//this does not
//linkTextView.font = UIFont(name: "ArialMT", size: 20)! // this works
ArialMT:
Ubuntu:
那我该如何解决呢?
答案 0 :(得分:0)
在设置属性字符串之前,您是否尝试过更改字体?
当textColor不受字体影响时,更改字体时可以删除下划线。
致谢