iOS Accessibility: make UITextField and specified subview accessible - ios

I want to make a textfield and a subview on the text field accessible by VoiceOver. If I use UIAccessibilityContainer methods, I can only make the subviews accessible. Is there some way to do this?

No. You must go up one level in the accessibility hierarchy. Implement the container protocol on your view's superview and return all of its descendants as children (and, thus, siblings of each other).

try this,
textfield.isAccessibilityElement = YES;
textfield.accessibilityElementsHidden = NO;
Leave the container methods for time being.

Related

Disable VoiceOver on a MapView [duplicate]

When I set isAccessibilityElement = NO on a view that contains subviews with isAccessibilityElement = YES, VoiceOver still detects them.
I need to switch off accessibility for an entire view hierarchy that must be handled differently by VoiceOver. How can I achieve this without having to loop through every single item in the object graph and mess with it's setting?
self.accessibilityElementsHidden = YES;
This makes all subviews hidden from accessibility.
I would try setting the accessibilityElementsHidden property of the main view to YES. If that does not what you want, I would try overriding the UIAccessibilityContainer methods on the main view to return 0 children.
Just set the accessibilityElementsHidden property.

Change accessibility reading order of UINavigationBar [duplicate]

Is it possible to change the order in which the VoiceOver feature for accessibility in iPad reads out the elements, when the 'Two-finger Flick Down' gesture is done?
For the attached image, which contains 3 labels and a button, the VoiceOver reads the elements in the following way,
Label 1 -> Label 2 -> Button -> Label 3
Can the order be changed to,
Label 1 -> Label 2 -> Label 3 -> Button
The quickest way to achieve this for your example is to place the three labels in a transparent UIView subclass to serve as a container for your labels. This subclass will have to be properly setup to let VoiceOver know how to interpret it. If your deployment target is iOS6 then you can simply answer the "should group accessibility children" question in this subclass.
-(BOOL)shouldGroupAccessibilityChildren{
return YES;
}
For below iOS6 it would be more complicated, except that your UIView container subclass would contain only UILabels which are accessibility elements. You could implement it like this:
-(BOOL)isAccessibilityElement{
return NO;
}
-(NSInteger)accessibilityElementCount{
return self.subviews.count;
}
-(id)accessibilityElementAtIndex:(NSInteger)index{
return [self.subviews objectAtIndex:index];
}
-(NSInteger)indexOfAccessibilityElement:(id)element{
return [self.subviews indexOfObject:element];
}
I have tested this example code and it does what you are looking for, if you need any clarification please add a comment. Always happy to help make things more accessible.
I tried setting the shouldGroupAccessibilityChildren to YES but it didn't work for me.
What did work for me was setting the accessibility label of the parent view directly (because I wanted all the items to be read in one go/one VoiceOver gesture).
[cell setAccessibilityLabel:[NSString stringWithFormat:#"%#, %#", cityLabel, temperatureLabel]];
The above snippet of codes is from Apple's documentation Enhancing the Accessibility of Table View Cells
In Swift, attaching an IBOutlet to the parent UIView, then setting shouldGroupAccessibilityChildren to true will suffice.
abc.shouldGroupAccessibilityChildren = true
I did note that if also setting isAccessibilityElement = true the grouping will not take effect. Similarly, checking the accessibility checkbox in the storyboard or xib will also prevent the grouping from taking place.
I think you can do it in the storyboard. The VoiceOver order is determined by the order of the views in the document outline.
Just drag and drop the views in the view hierarchy in the right order.

iOS add view to Button in IB

I am trying to add a view on a UIButton inside IB. The only problem it doesn't allow me to put in inside the button only on top?
Is this not possible through IB or am I doing it wrong?
It's not possible in Interface Builder. You have to add it in code.
You should not do this:
Do Not Customize Controls by Embedding Subviews
Although it is technically possible to add subviews to the standard system controls—objects that inherit from UIControl—you should never customize them in this way. Controls that support customizations do so through explicit and well-documented interfaces in the control class itself. For example, the UIButton class contains methods for setting the title and background images for the button. Using the defined customization points means that your code will always work correctly. Circumventing these methods, by embedding a custom image view or label inside the button, might cause your application to behave incorrectly now or at some point in the future if the button’s implementation changes.
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW26
If you need to add a UIView on your UIButton you can achieve it in 2 different ways
The easy way is to follow Cyrille answer: you can do it programmatically because IB doesn't allow you to modify a UIBUtton adding a view on it
The hard way is to create your custom button (let me call it "MYCustomButton"), that extends a UIButton, and use it in your application. With this way when you need to modify the buttons in your interface, you can achieve it modifying the XIB of the "MYCustomButton".

ios uibutton hidden: does this automatically make the button disabled?

I just have a knowledge question about UIButtons / iOS in general.
Let's say you have a UIButton. You set the 'hidden' property to YES. This makes it no longer visible in view, right? But I noticed that while it's no longer visible, it is also no longer clickable either. So, does this mean that setting hidden = YES also sets enabled = NO?
Just curious. Thanks y'all.
UIButton and all controls inherits common properties from UIView like hidden, backgroundColor, etc.
Class reference of UIView says if any view is hidden then it will not receive input events
Class reference of UIView says:
A hidden view disappears from its window and does not receive input
events. It remains in its superview’s list of subviews, however, and
participates in autoresizing as usual. Hiding a view with subviews has
the effect of hiding those subviews and any view descendants they
might have. This effect is implicit and does not alter the hidden
state of the receiver’s descendants.
you can find this over Here.
It does. Setting the buttons hidden property to YES will disable any user interaction. This is true for other UI elements as well as just UIButton.
Yes you can't touch button when it is hidden.If you wanna touch it then you must make it btn.hidden = NO;. Hidden means disable the user interaction.
Not sure. Best way to find out would be an NSLog returning button.hidden

Accessibility for iOS, VoiceOver read order issue

Is it possible to change the order in which the VoiceOver feature for accessibility in iPad reads out the elements, when the 'Two-finger Flick Down' gesture is done?
For the attached image, which contains 3 labels and a button, the VoiceOver reads the elements in the following way,
Label 1 -> Label 2 -> Button -> Label 3
Can the order be changed to,
Label 1 -> Label 2 -> Label 3 -> Button
The quickest way to achieve this for your example is to place the three labels in a transparent UIView subclass to serve as a container for your labels. This subclass will have to be properly setup to let VoiceOver know how to interpret it. If your deployment target is iOS6 then you can simply answer the "should group accessibility children" question in this subclass.
-(BOOL)shouldGroupAccessibilityChildren{
return YES;
}
For below iOS6 it would be more complicated, except that your UIView container subclass would contain only UILabels which are accessibility elements. You could implement it like this:
-(BOOL)isAccessibilityElement{
return NO;
}
-(NSInteger)accessibilityElementCount{
return self.subviews.count;
}
-(id)accessibilityElementAtIndex:(NSInteger)index{
return [self.subviews objectAtIndex:index];
}
-(NSInteger)indexOfAccessibilityElement:(id)element{
return [self.subviews indexOfObject:element];
}
I have tested this example code and it does what you are looking for, if you need any clarification please add a comment. Always happy to help make things more accessible.
I tried setting the shouldGroupAccessibilityChildren to YES but it didn't work for me.
What did work for me was setting the accessibility label of the parent view directly (because I wanted all the items to be read in one go/one VoiceOver gesture).
[cell setAccessibilityLabel:[NSString stringWithFormat:#"%#, %#", cityLabel, temperatureLabel]];
The above snippet of codes is from Apple's documentation Enhancing the Accessibility of Table View Cells
In Swift, attaching an IBOutlet to the parent UIView, then setting shouldGroupAccessibilityChildren to true will suffice.
abc.shouldGroupAccessibilityChildren = true
I did note that if also setting isAccessibilityElement = true the grouping will not take effect. Similarly, checking the accessibility checkbox in the storyboard or xib will also prevent the grouping from taking place.
I think you can do it in the storyboard. The VoiceOver order is determined by the order of the views in the document outline.
Just drag and drop the views in the view hierarchy in the right order.

Resources