setting an accessibilityLabel on a UIImageView con

2019-03-18 17:57发布

I have a UITableView that I build in loadView. One of the things I do in loadView is create a UIView to act as the table header and stuff a UIImageView into it. The image view contains an image that is a stylized title, so I want to add an accessibility label for VoiceOver users. However, I can't get VoiceOver to "focus" on the image in order to read the label, and the Accessibility Inspector doesn't respond to clicking on the image in the simulator. My (abbreviated) code follows:

... in -loadView ...
// Make header view
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(...)];
UIImageView *titleImageView = [[UIImageView alloc] initWithImage:[self titleImage]];
titleImageView.accessibilityLabel = [self accessibilityLabelForTitleImage];
[headerView addSubview:titleImageView];

// Make table view
self.tableView = [[UITableView alloc] initWithFrame:CGRect(...) style:UITableViewStylePlain];
self.tableView.tableHeaderView = headerView;
... code continues ...

I've stepped through in gdb and accessibilityLabelForTitleImage returns a string. po [titleImageView accessibilityLabel] prints out the correct string, but I'm still unable to focus on the image view. Note that the views themselves appear and respond as appropriate.

Am I missing something? Is there a way to force VoiceOver to acknowledge an image view?

3条回答
成全新的幸福
2楼-- · 2019-03-18 18:26

Voice-Over sometimes can get nasty and just by setting isAccessibilityElement might not work.

In this case try setting accessibilityElements on the parent view and include the child views in the array, like this:

parentView.accessibilityElements = [childView1, childView1, childView1]

Doing it also ensures that the accessibility items are being read in the order you want.

查看更多
【Aperson】
3楼-- · 2019-03-18 18:33

I used KIF for testing my IOS app. In my tableview, I assigned value to tableview.accesssibilityIdentifier instead of tableview.accessibilityLabel. It worked for me. Wanna give it a try?

查看更多
一纸荒年 Trace。
4楼-- · 2019-03-18 18:45

In Voice-Over , in order to make an element accessible :-

  1. you have to set setIsAccessibilityElement property as true which i don't find in your code.

  2. The other important point is that to make child elements (subviews) to be accessible , you have to seperately make them accessible while the parent should not be accessible(you have to specify this also).

  3. Implement the UIAccessibilityContainer Protocol in your custom - cell.

It will be a big story if i go on .Please refer this Accessibility voice over by apple.

Hope this helps.

查看更多
登录 后发表回答