If you need multiple links embedded in some text (like the classic T&Cs and Privacy policy), the easiest is to use a UITextView & Attributed Strings, and it will work beautifully with VoiceOver. You'll be even able to navigate through links.

App shows a registration form with username and password textfields and a text that says “I agree with the Privacy Policy and the Terms and Conditions” Both Privacy Policy and Terms and Conditions are links. There is some code that shows you how you can use a text field with attributed strings and the link attribute. Implementing the UITextViewDelegate has a function to capture link interactions so they can be handled.

In the example, VoiceOver would say: “I agree with the Privacy Policy and the Terms and Conditions, link”. Swipe down, should announce: “Privacy Policy, link” and you can double tap to open it. Swiping down one more time announces: “Terms and Conditions, link”.

Example code in the image:

let textView = UITextView()
let string = "I agree with the Privacy Policy and the Terms and Conditions"
let attributedString = NSMutableAttributedString(string: string)

attributedString.addAttribute(.link,
                              value: "https://www.yourdomain.com/pp",
                              range: NSRange(location: 17, length: 14))
attributedString.addAttribute(.link,
                              value: "https://www.yourdomain.com/tac",
                              range: NSRange(location: 40, length: 20))
textView.attributedText = attributedString

extension ViewController: UITextViewDelegate {
    func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
        UIApplication.shared.open(URL)
        return true
    }
}

You may also find interesting...

It is possible to embed icons within text using NSTextAttachment and NSAttributedString. If you do, please remember to override the accessibility label, otherwise VoiceOver will announce it as "Attachment.png File". Example code in the image: ```swift let magnifyingGlassIcon = UIImage(systemName: "magnifyingglass")! let searchButton = UIButton() let searchTutorialLabel = UILabel() searchButton.accessibilityLabel = "search" let textAttachment = NSTextAttachment(image: magnifyingGlassIcon) let string = "Select the button to find elements in the list" let attributedString = NSMutableAttributedString(string: string) let attributedStringIcon = NSAttributedString(attachment: textAttachment) let iconPlaceholderRange = attributedString.string.range(of: "")! let iconRange = NSRange(iconPlaceholderRange, in: attributedString.string) attributedString.replaceCharacters(in: iconRange, with: attributedStringIcon) searchTutorialLabel.attributedText = attributedString searchTutorialLabel.accessibilityLabel = string.replacingCharacters(in: iconPlaceholderRange, with: searchButton.accessibilityLabel!) ```

Images can automatically scale for accessibility content size categories, by setting the adjustsImageSizeForAccessibilityContentSizeCategory property to true, for any UIImageView you'd like to get its size adjusted. https://developer.apple.com/documentation/uikit/uiaccessibilitycontentsizecategoryimageadjusting/adjustsimagesizeforaccessibilitycontentsizecategory

If you need to send announcement notifications that can step into each other, they will by default, interrupt ongoing announcements. But you can pass attributed strings as parameters too, letting you specify announcements to be queued.

Created in Swift with Ignite.

Supporting Swift for Swifts