Skip to content

Instantly share code, notes, and snippets.

@fahied
Created July 1, 2015 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fahied/f45e03c260f9e0f7ef57 to your computer and use it in GitHub Desktop.
Save fahied/f45e03c260f9e0f7ef57 to your computer and use it in GitHub Desktop.
add UIAccessiblity to UICollectionViewCell
// Option 1: In ViewController, set the cell instance to have accessibility.
Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
[cell setIsAccessibilityElement:YES];
// Option 2: Implement the accessibility interface in the cell object:
// implementation file of Cusome CollectionViewCell
- (BOOL)isAccessibilityElement
{
return YES;
}
- (NSString *)accessibilityLabel {
return self.label.text;
}
- (UIAccessibilityTraits)accessibilityTraits {
return UIAccessibilityTraitStaticText; // Or some other trait that fits better
}
- (void)accessibilityElementDidBecomeFocused
{
UICollectionView *collectionView = (UICollectionView *)self.superview;
[collectionView scrollToItemAtIndexPath:[collectionView indexPathForCell:self] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally|UICollectionViewScrollPositionCenteredVertically animated:NO];
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment