简体   繁体   中英

How to make links within a label text be available for voice over (accessibility)? (iOS, Xamarin)

I have a method to insert hyperlinks into parts of a UILabel text using attributed string (underlined range). So a label might have none, one or more links to it. There is a tap gesture on the label, on which I can determine which part of the text the user is touching and trigger the appropriate action. This part is all tested and works fine.

When it comes to accessibility voice over it doesn't work very well. Only scenario that works is to set the whole label to be accessed by using:

LabelMessage.IsAccessibilityElement = true;
LabelMessage.AccessibilityTraits = UIAccessibilityTrait.Link;

My difficulty lies on having the user to be able to click on links inside that label with voice over. Voice over doesn't know that there are links inside that label. So it reads the whole label as one. I would like the voice over to read the label but when user clicks on part of the text that has a link, voice over would highlight just that part of the text and with a double click the action would be performed. I am not even aware that this is even achievable. Any insights on this matter would be really appreciated.

As one commentor mentioned, custom actions would be a good place to start. You can also add custom rotor with system type UIAccessibilityCustomRotor.SystemRotorType.link to your view so that VoiceOver users can navigate multiple links in a label.

For an introduction to custom rotors, you can watch https://developer.apple.com/videos/play/wwdc2020/10116/ .

Lastly, changing to a UITextView might also automatically solve this issue.

The best solution so far for this problem is to use UIAccessibilityCustomAction as @Junior Jiang mentioned on one of the comments.

Rotors are definitely not the solution. However, rotors can be used for UITextView as they have UITextRange property which can be used to navigate throughout the text.

Custom actions are much simpler to use than rotors and they work at the label level.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM