我们已经实现了一个代码,可以在UITextView中添加到整个属性文本的链接。
我们正在加载的字符串是:
英语字符串:“单击此处查看”,阿拉伯文字符串:“”انقرهناللعرض“
func setupTextView() {
let mutableAttributedString = NSMutableAttributedString(string: "")
let attributedString = NSAttributedString(string: {string value}, attributes:
[NSAttributedString.Key.foregroundColor:Colors.gray_3_748499])
mutableAttributedString.append(attributedString)
mutableAttributedString.addAttribute(NSAttributedString.Key.link, value:
"https://www.google.com", range: NSMakeRange(0, self.attributedString.length))
self.textView.attributedText = mutableAttributedString
}
结果:我们可以看到,对于所有其他必需的语言,单击文本后,代表textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction)
被调用,但阿拉伯语不被调用。
期待有价值的建议。
我知道了。我已经覆盖了
func point(inside point: CGPoint, with event: UIEvent?) -> Bool
忽略任何位置的水龙头的方法,但不忽略文本视图中的链接。
我在此方法内部使用了UITextLayoutDirection。我必须根据不同语言的对齐方式对其进行更改。那是从右到左的语言,我将使用UITextLayoutDirection.Right。
谢谢