Re: Creating Accessibility Elements for Links in UITextView
Re: Creating Accessibility Elements for Links in UITextView
- Subject: Re: Creating Accessibility Elements for Links in UITextView
- From: Chris Fleizach <email@hidden>
- Date: Mon, 23 Nov 2015 11:57:22 -0800
Sent from my iPhone
> On Nov 23, 2015, at 12:55 AM, Kenny Carruthers <email@hidden> wrote:
>
> Chris,
>
> Thanks for the reply.
>
> Using a standard UILabel, its attributedText property is being properly set and any links that are annotated within an NSLinkAttributeName are being correctly displayed by UILabel. However, VoiceOver does not recognize the links as being separate accessibility elements. So, VoiceOver just highlights the entire UILabel and, effectively, ignores the embedded links. This kind of makes sense to me because in a standard UILabel, links are correctly displayed but they aren't user interactive.
For these elements the links appear in the rotor. You can rotate two fingers until you hear "links" and then swipe up or down to select a link. Then double tap to activate
You can see an example in setting > general > Siri
> To work around this, I subclassed UILabel to add support for two things:
>
> - Touch detection on the links.
> - Custom accessibility elements.
>
> So, to answer your question, a subclass of UILabel is my "accessibility container". I configure it as follows:
>
> - return NO from isAccessibilityElement
> - return 1+n accessibility elements from the "accessibilityElements" property.
> - One element is for the entire label and has a frame that matches the labels frame.
> - The other elements are frames for each link within the attributedText.
>
And the accessibility container for each element is the label itself? Do you return the same elements each time or are you making new objects on each call of accessibilityElements? ( you'll want to do the former)
> Everything seems to be working *after* the label is first tapped on by the user. If the user does not tap on the label, then VoiceOver appears to not recognize it as an accessibility element when swiping through elements on the screen. (Though isAccessibiityElement is called).
>
> Maybe I shouldn't be trying to override UILabel and/or there are a few more methods I do need to override. Not sure.
>
> Thanks,
> Kenny
>
>> On Nov 23, 2015, at 3:01 PM, Chris Fleizach <email@hidden> wrote:
>>
>>
>>> On Nov 22, 2015, at 8:48 AM, Kenny Carruthers <email@hidden> wrote:
>>>
>>> Hello,
>>>
>>> I have a block of text that I need to show to the user in an iOS app. The requirements are as follows:
>>>
>>> - Links must be detected
>>> - Each link must be recognized as a VoiceOver element
>>> - Each paragraph must be recognized as a VoiceOver element.
>>>
>>> Is there a way to configure UITextView (or UILabel for that matter) to satisfy all these requirements? An attributed string is used as the text. (Which was read from an RTF document.)
>>>
>>> Obviously, getting link detection to work is straight forward, but the links are not detected by VoiceOver. And if multiple paragraphs are present, then they are not broken up by VoiceOver either. Using a WebView almost works, but it we're not particularly interested in using HTML for everything.
>>>
>>> One attempt was to create a new UILabel subclass for every paragraph in the text and lay them out using a stack view. This works fine and satisfies the third requirement. With some custom code I can also detect links and touches in a UILabel subclass and that works as well. However, when I attempt create accessibility elements I run into some problems.
>>>
>>> (This is in a UILabel subclass). I convert the label to be an accessibility container by returning "NO" to "isAccessibilityElement". I then create two accessibility elements: one for the label itself and a second one for the link. That appears to work, but it suffers from one big problem: VoiceOver does not recognize the custom accessibility elements until after the user has clicked on the label. (So in a few with 5 labels laid out top to bottom, VoiceOver does not see any accessibility elements until you tap on them, after which it sees each element you've tapped on.)
>>>
>>> My guess is that hijacking a UILabel's accessibility elements might not be supported (or I'm doing it wrong). Regardless, any thoughts as to how to go about satisfying the requirements above?
>>
>> There’s not a way to have VO recognize paragraphs of text as separate elements.
>>
>> You should be able to get the links to appear if you use attributedText and mark your link ranges with NSLinkAttributeName
>>
>> However, your current solution should also work, but it sounds like you cannot swipe to reach these elements, they only work when you touch on them.
>>
>> That often happens when you have these fake elements and they either
>> a) Don’t have the correct accessibilityContainer
>> b) The accessibilityContainer does not return the right elements in accessibilityElements
>>
>> What is the container that is returning these elements?
>>
>> Thx
>>
>>> Thank you,
>>> Kenny
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Accessibility-dev mailing list (email@hidden)
>>> Help/Unsubscribe/Update your Subscription:
>>>
>>> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden