Suraj K Thomas
Suraj K Thomas

Reputation: 5883

How to add accessibilitylabel for UISearchBar IOS

self.searchbar.isAccessibilityElement=YES;
self.searchbar.accessibilityLabel=@"searchbar";
self.searchbar.accessibilityHint=@"searchbar";
self.searchbar.accessibilityElementsHidden=NO;

The above code i have added for a UISearchbar outlet in ViewDidLoad.Unfortunately accessibility labels are not getting displayed.I used the above code for all UIelements and works fine except for UISearchbar.Do we have to use UIAccessibilityContainer for UISearchbar?

Upvotes: 3

Views: 3051

Answers (2)

chirag agarwal
chirag agarwal

Reputation: 21

try to add the accessibility label to text field property of searchBar

Upvotes: 2

user4549597
user4549597

Reputation:

You need to tell iOS which accessibility trait best characterizes the object. In this case you want:

self.searchbar.accessibilityTraits = UIAccessibilityTraitSearchField;

You may also want to have a look Apple's UIAccessibilityTraits documentation.

Upvotes: 7

Related Questions