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;
Related
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.
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
I have a UICollectionView and I want some of my cells to be disabled. That means I want the cell to look a bit greyer (to have a disabled feeling), and I want the user to not be able to click on the cell.
I know I can use the alpha parameter and set it to something like 0.7, but this gets disabled while moving the cells around, and also it doesn't look grey enough. So I'm looking for another option to do it.
For controlling the tapping on a cell, I know I can use collectionView:didSelectItemAtIndexPath: and check for the indexPath. But I was wondering if there's another option for disabling a cell, like there is for disabling a UIButton: myButton.enabled = NO.
You can always set userInteractionEnabled to NO for the UICollectionViewCell and any taps inside it will be ignored.
Your problem with the alpha sound like you need to do some more work in prepareForReuse, or implement prepareForReuse in your custom cell class if you have not already done so.
I’m implementing accessibility in a custom UITableViewCell class. I have a fairly simple overflow menu with a couple of buttons inside it, which are hidden until an ellipsis button is pushed that slides open and closes the overflow.
In my cell's initialiser I’m setting the accessibilityElementsHidden of my overflowContainer to YES. This seems to work, when scrolling through using VoiceOver, those views are skipped.
Then, when opening the cell, in the completion handler of the UIView animation, I set that same accessibilityElementsHidden of the same overflowContainer to NO. This doesn’t seem to have any effect, those elements are still skipped.
I’ve also tried posting UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil) before / after / when changing the accessibilityElementsHidden BOOL, but this also appears to have no effect on the situation.
Basically I’d like to toggle accessibilityElementsHidden on a couple of UIView instances at a specific point. Could anyone let me know what I may be doing wrong?
Here’s the code I fire when the overflow opens:
- (void)cellOverflowDidShow:(MyCell *)cell
{
self.overflowContainer.isAccessibilityElement = YES;
self.firstButton.isAccessibilityElement = YES;
self.secondButton.isAccessibilityElement = YES;
self.thirdButton.isAccessibilityElement = YES;
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.firstButton);
}
I fire the opposite when closing the cell (set all to NO and post notification again). And when initializing the cell, all I set is:
self.overflowContainer.isAccessibilityElement = NO;
Absolutely no idea why it shouldn’t be working, it appears I’m doing everything 100% correctly. If I don’t set the line in the initializer, the buttons all appear accessible (all the time). So it appears that the first call, be it YES or NO, works, but any subsequent ones are ignored.
In the visible state, you declare the overflow container to be an accessibility element. Thus, VoiceOver will allow the user to focus it rather than navigate child elements. Instead of toggling whether it's an accessibility element, keep self.overflowContainer.isAccessibilityElement set to NO and toggle the accessibility of its children, firstButton, secondButton, and thirdButton.
A shorthand for setting the accessibility of child elements is accessibilityElementsHidden. Try setting self.overflowContainer.accessibilityElementsHidden to NO when the view appears and YES when it disappears.
You may still need to trigger a layout change notification, regardless.
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.