链接不是斯威夫特4
问题描述:
我使用的是iOS 11和斯威夫特4.链接不是斯威夫特4
工作我试图以编程方式产生UITextView
内的链接。
所有的属性都起作用(即颜色,大小,范围等) - 但不幸的是,链接不起作用。有人可以告诉我为什么吗?
这里是我的代码:
@IBOutlet weak var textView: UITextView!
// Setting the attributes
let linkAttributes = [
NSAttributedStringKey.link: URL(string: "https://www.apple.com")!,
NSAttributedStringKey.font: UIFont(name: "Helvetica", size: 18.0)!,
NSAttributedStringKey.foregroundColor: UIColor.blue
] as [NSAttributedStringKey : Any]
let attributedString = NSMutableAttributedString(string: "Just click here to do stuff...")
// Set the 'click here' substring to be the link
attributedString.setAttributes(linkAttributes, range: NSMakeRange(5, 10))
self.textView.delegate = self
self.textView.attributedText = attributedString
同样,链接似乎是正确的,但点击它不工作。
下面是截图:
谢谢!我看起来太过分了。有趣的是,从Swift3切换到Swift4这个'可编辑'和'可选'属性以某种方式在故事板内部混乱了(因为在它工作正常之前)。最好以编程方式完成 - 谢谢! – iKK