func configureTextView() {
textView.isSelectable = true
textView.isEditable = false
let attributedString = NSMutableAttributedString(string: Subscription.smsPriceDisclaimer)
if let range = Subscription.smsPriceDisclaimer.range(of: Subscription.termsOfUse), let url = URL(string: AppURL.Shop.URL.termsOfUse) {
attributedString.addAttribute(.link, value: url, range: Subscription.smsPriceDisclaimer.nsRange(from: range))
}
if let range = Subscription.smsPriceDisclaimer.range(of: Subscription.privacyPolicy), let url = URL(string: AppURL.Shop.URL.policiesAndDisclosures) {
attributedString.addAttribute(.link, value: url, range: Subscription.smsPriceDisclaimer.nsRange(from: range))
}
if let range = Subscription.smsPriceDisclaimer.range(of: Subscription.noticeOfFinancialIncentive), let url = URL(string: AppURL.Shop.URL.noticeOfFinancialIncentive) {
attributedString.addAttribute(.link, value: url, range: Subscription.smsPriceDisclaimer.nsRange(from: range))
}
// Set the 'click here' substring to be the link
let textAttributes: [NSAttributedString.Key : Any] = [
NSAttributedString.Key.foregroundColor: Style.Color.universal_757575,
NSAttributedString.Key.font: UIFontMetrics.default.scaledFont(for: UMAStaticFont.dealCardDescriptionNS)
]
attributedString.addAttributes(textAttributes, range: NSMakeRange(0, Subscription.smsPriceDisclaimer.count))
textView.linkTextAttributes = [
.underlineStyle: NSUnderlineStyle.single.rawValue
]
textView.delegate = self
textView.isUserInteractionEnabled = true
textView.attributedText = attributedString
}
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
if interaction == .invokeDefaultAction, URL.scheme?.starts(with: "http") ?? false {
let start = textView.text.index(textView.text.startIndex, offsetBy: characterRange.location)
let end = textView.text.index(textView.text.startIndex, offsetBy: characterRange.location + characterRange.length)
let range = start..<end
let titleVal = String(textView.text[range])
delegate?.showWebview(urlString: "\(URL)", titleValue: titleVal)
return false
}
return true
}
As there are 3 attributed links inside textview on running accessibility inspector links are not accessible separately. can someone suggest how to make voice-over working.