Created
July 1, 2015 10:11
-
-
Save fahied/f45e03c260f9e0f7ef57 to your computer and use it in GitHub Desktop.
add UIAccessiblity to UICollectionViewCell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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