0

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.

Gustavo Baiocchi Costa
  • 1,379
  • 3
  • 16
  • 34
  • Hi, do you mean that **VoiceOver** only can read the text of `UIlable` but can not invoke the click event? – Junior Jiang Oct 23 '20 at 03:00
  • 1
    Maybe, this discussion will be helpful: https://stackoverflow.com/questions/39522364/uitextview-linkable-label-accessibility-voice-over-issue You could have a look at it. In addition, [UIAccessibilityCustomAction](https://developer.apple.com/documentation/uikit/uiaccessibilitycustomaction?language=objc) could make a custom action to be performed on an accessible object. – Junior Jiang Oct 23 '20 at 03:20
  • @JuniorJiang-MSFT That is correct. I will have a look at that link you sent, seems to address my problem – Gustavo Baiocchi Costa Oct 23 '20 at 10:45
  • @JuniorJiang-MSFT I couldn't get anything working yet. I had to move away from this bug temporary as it was taking too long to resolve it. But I am still finding ways to solve this. I tried to follow the tips on those questions but nothing seems to work so far ;( – Gustavo Baiocchi Costa Oct 28 '20 at 17:29

2 Answers2

0

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.

Alex Walczak
  • 1,276
  • 1
  • 12
  • 27
  • I was setting the trait of the label as link without much change on behaviour. I will try to implement the rotor. Gonna have to identify the links in the label as my implementation of links is a bit complex. Thanks – Gustavo Baiocchi Costa Nov 09 '20 at 13:12
  • I have further investigated this and UILabel cannot be traversed like UITextView can. You will need UITextRange and UILabel does not have that. Also, rotors are for the whole page/controller instead of a single view/label within a page. – Gustavo Baiocchi Costa May 18 '22 at 10:40
0

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.

Gustavo Baiocchi Costa
  • 1,379
  • 3
  • 16
  • 34
  • Do you have an example of how you used UIAccessibilityCustomAction to access links in UILabel? – SRIRAM Sep 12 '22 at 17:35