Accessibility link - iOS

On iOS, links should contain the link attribute. This attribute can be added through the addAttribute method of NSMutableAttributedString

To create text links, you can show the attributed string by using the the attributedText property of UILabel.

Depending on how your links are created, you might need to set the .link trait as accessibilityTraits.

guard let url = URL(string: "https://appt.org") else { return }
let link = "Appt"

let attributedString = NSMutableAttributedString(string: "Learn more about \(link)")

let range = attributedString.mutableString.range(of: link)
attributedString.addAttribute(.link, value: url, range: range)

let label = UILabel()
label.attributedText = attributedString

// Optional: add .link accessibility trait to whole label
label.accessibilityTraits = .link