I'm trying to improve Voice Over support in an app. I have a UISearchBar
. I've set the showBookMarks
property to YES
. And I've set a custom image with:
[searchbar setImage:icon forSearchBarIcon:UISearchBarIconBookmark state:UIControlStateNormal];
The problem I have is that with Voice Over turned on, there is no way to activate the bookmarks icon. If I enter text, the "clear" icon appears and it can be selected and activated as expected. But once the text is cleared and my bookmarks icon appears, it can't be selected. No matter where I tap, the Voice Over rectangle always surrounds the entire search bar, including the icons.
I've tried setting the accessibilityLabel
and the accessibilityTraits
properties on the UIImage
for the icon. I've set the UIImage
's isAccessibilityElement
property to YES
. Nothing seems to work.
Does anyone know what steps are required to make the bookmarks icon in a UISearchBar
accessible?
Here's the complete code for the search bar:
UISearchBar *bar = [[UISearchBar alloc] init];
[bar sizeToFit];
bar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
bar.placeholder = @"Search listed items";
bar.autocapitalizationType = UITextAutocapitalizationTypeNone;
bar.autocorrectionType = UITextAutocorrectionTypeNo;
bar.keyboardType = UIKeyboardTypeDefault;
bar.showsBookmarkButton = YES;
bar.text = @"";
UIImage *icon = [UIImage imageNamed:@"bookmarks.png"];
icon.accessibilityLabel = @"Bookmarks";
icon.accessibilityTraits = UIAccessibilityTraitButton;
icon.isAccessibilityElement = YES;
[bar setImage:icon forSearchBarIcon:UISearchBarIconBookmark state:UIControlStateNormal];
[bar setPositionAdjustment:UIOffsetMake(-1, -1) forSearchBarIcon:UISearchBarIconBookmark];
Additional Info:
I should mention that the search bar is used with a UITableViewController
which is connected with a UISearchDisplayController
. The search bar is being set as the table view's headerView
.
And all of this is done in code. No storyboards or xibs are involved.