How to add accessibilitylabel for UISearchBar IOS - 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?

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.

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

Related

XCTest: How to correctly setup Accessibility Traits for UITextView?

I have a UITextView with Accessibility Identifier properly set up. When I try to hook this element usingapp.textViews["textViewIdentifier"] it does not work.
It probably does not work because I'm not setting up accessibility traits correctly. I don't see any traits available for UITextView in interface builder or documentation
Playing with different traits I was able to find the textview but it does not execute textView.typeText("test text") since traits don't match with type.
TextView is contained only in default UIView.
After more testing, the core of issue seems to setting up Accessibility traits correctly for UITextView. How do you correctly setup Accessibility Traits for UITextView?
As far as I understand your post, there are two questions here:
How do I set up an Accessibility Identifier
How do I type text in my textview during a UI test
I can answer the second question. You can either use po app.textViews in a breakpoint to see the identifier, or, if the textview is the only one on the page, use app.textViews.firstMatch.
If you need an answer to the first question I will leave that to someone else.

Disable RTL direction for UICollectionView

I'm building a custom calendar view with UICollectionView. Everything is pretty well but when I tried to test when language is set to Arabic, the cells are listed from right to left. Is there a way to disable this in RTL mode.
I have checked the documentation but there is no such option.
You can disable it by setting view semantics property
You have to set it on UICollectionView
there is a property in UIView Class
semanticContentAttribute
with following value
UISemanticContentAttributeUnspecified = 0,
UISemanticContentAttributePlayback,
UISemanticContentAttributeSpatial,
UISemanticContentAttributeForceLeftToRight,
UISemanticContentAttributeForceRightToLeft
To Disable RTL on specific view in Swift 4.
myView.semanticContentAttribute = .unspecified

Swipe to switch focused accessibility element iOS

When the user has Voice Over on in certain apps, a one handed swipe to the right or the left changes the focused accessibility element and speaks it (for example, the App Store top charts view). I would like to have this in my own app (which uses a storyboard).
I can think of several ways to do this myself with a swipe gesture recognizer and a list of accessibility elements in order, but it seems like there must be a way to do this in the accessibility API. However, my research has turned up nothing.
Is this a built in feature? If so, how can I add it in my storyboard or in code?
Edit:
Per advice from one of the answer I have implemented the UIAccessibility protocol for my view.Here is the code.
- (NSInteger)accessibilityElementCount{
return 4;
}
- (id)accessibilityElementAtIndex:(NSInteger)index{
return [#[self.menuButton, self.firstButton, self.secondButton, self.thirdButton] objectAtIndex:index];
}
- (NSInteger)indexOfAccessibilityElement:(id)element{
return [#[self.menuButton, self.firstButton, self.secondButton, self.thirdButton] indexOfObject:element];
}
The view I am having this issue with is defined in an interface builder storyboard. As you can no doubt infer from the code, it has 3 buttons as subviews.
What you are describing is the built-in behavior for VoiceOver and can't be changed on a per-app basis.
If you want to modify the order elements are focused, look at the UIAccessibilityContainer protocol for iOS 7 or accessibilityElements property of NSObject for iOS 8. If you don't want to implement either of those, you can also simply set accessibilityElementsHidden to YES for elements you want VoiceOver to ignore.
I have fixed the problem by adding accessibility labels to the buttons in the storyboard. Because voice over already spoke their label correctly, I had not bothered to do so before.

Customize uikeyboardtype with #gmail.com and numbers

I want to create a UIKeyboard type that will look like the following.
This app is only for iPad and none of the default keyboard type seem to match.
Any suggestions for adding buttons to the keyboard type?
I may be wrong, but what that looks like is the standard keyboard with a custom toolbar on top. It was most likely done using the inputAccessoryView property for the textfield:
[textField setInputAccessoryView:inputAccView];
Here is where I took the example from.
As far as I am aware, this is not supported in a super easy way by default iOS system keyboards.
However, you can specify your own UIView as an "input accessory view" for a text field.
Specifically, look at this method in the UITextField documentation:
inputAccessoryView.
So you should just be able to create a UIView, style it to look very similar to the usual system keyboard UI, add UIButtons, and set it as the "input accessory view"
But you will have to do your own work to make the background of the accessory view and the buttons on it fit well with the system keyboard.

iOS - Can I disable accessibility on cell.textLabel.text?

I have an app that contains a view with a cell that uses the built-in cell.textLabel and a custom UITextField in cell.contentView.
I am working with Voiceover and accessibility and the desired behavior would be that whenever I tap anywhere in the cell, the accessibility element for the UITextField would be selected.
The behavior that I am actually seeing is that the cell.textLabel accessibility labels are taking over. When I don't have cell.textLabel set to anything, everything works as expected. I have also attempted to set the "isAccessibilityElement" property with no luck:
[cell.textLabel.text setIsAccessibilityElement:NO];
Does anyone know how to make this work the way I want?
I was able to figure this out using this:
cell.textLabel.accessibilityElementsHidden = YES;

Resources