当语言为阿拉伯语时,链接在 UITextView 属性字符串中不起作用

Links not working in UITextView Attributed String when language is Arabic

我们已经实现了一个代码,可以将 link 添加到 UITextView 中的整个属性文本。

我们正在加载的字符串是:

英文字符串:"Click Here To View", 阿拉伯字符串: "انقر هنا للعرض"

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.

谢谢