VoiceOver finds a blank line on both sides of a UITextView

I have a table view in which cells contain only UITextView, configured as such:

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; // Declare and set text & frame ... UITextView *textView = [[UITextView alloc] initWithFrame:frame]; textView.backgroundColor = [UIColor clearColor]; textView.editable = NO; textView.font = font; textView.scrollEnabled = NO; textView.text = text; [cell.contentView addSubview:textView]; 

When I test the VoiceOver application, I can find two places that are just small empty elements for which VoiceOver says โ€œempty lineโ€ on the left and right edges of the text in the text view. If I have a multi-line string, for example. @"multiple\nlines" , then on the right edge of the first line there is an "empty line", and the other on the left edge of the second line. I cannot find the "empty line" to the left of the first line or to the right of the second line, but as far as I know, they are simply difficult to find.

Why does VoiceOver find these blank lines? How can I get rid of them?

+6
source share
1 answer

Here is a workaround for this error we encountered today.

Subclass of UITextView and Overriding:

 - (BOOL)isAccessibilityElement { return NO; } 

Returning NO cancels VoiceOver. Then make a container by adding a text view to it and set a custom accessibilityLabel label in the container view:

 containerView.accessibilityLabel = textview.text 

This obviously will not work for some cases (I didnโ€™t study editing very much), but at least it gets to the place where the text view does not display the behavior in question.

0
source

All Articles