Accessibility link on iOS
Links should be accessible for users of assistive technologies. When accessibility is not taken into account, users might not be able to find or activate links.
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
.
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