首页 > 解决方案 > 旁白未检测到 UITextView (iOS 13) 中的链接

问题描述

旁白未检测到 UITextView (iOS 13) 中的链接

我有以下代码,它适用于 iOS 12 上的配音(即配音在向上/向下滑动时选择单个链接)但在 iOS 13 上向上/向下滑动不起作用

class ViewController: UIViewController {

@IBOutlet weak var myTextView: UITextView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        let text = "Testing https://www.google.com/ in link and 904-567-5678 is phone number"
        let attributedString = NSMutableAttributedString(string: text)

        myTextView.attributedText = attributedString
        myTextView.isUserInteractionEnabled = false
        myTextView.isEditable = false
        myTextView.isSelectable = true
        myTextView.dataDetectorTypes = [.link,.phoneNumber]
        myTextView.font = UIFont(name: myTextView.font!.fontName,
                                 size: 25.0)
        myTextView.backgroundColor = .red
    }


    func textView(_ textView: UITextView,
                  shouldInteractWith URL: URL,
                  in characterRange: NSRange,
                  interaction: UITextItemInteraction) -> Bool {

        UIApplication.shared.open(URL, options: [:])
        return false
    }

}

标签: iosswiftuitextviewvoiceoveruiaccessibility

解决方案


如果这在 iOS 13 中仍然不起作用,作为一种解决方法,您可以执行以下操作:

attributedString.addAttribute(.link, value: myLinkURL, range: NSRange(myLinkLocation...)


推荐阅读