Created
January 10, 2012 00:54
-
-
Save justin/1586076 to your computer and use it in GitHub Desktop.
UIAccessibilityElement Example
This file contains hidden or 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
NSUInteger numberOfSegments = [self numberOfSegments]; | |
CGFloat segmentWidth = CGRectGetWidth(self.bounds) / numberOfSegments; | |
CGFloat segmentHeight = CGRectGetHeight(self.bounds); | |
UIAccessibilityElement *element = [[UIAccessibilityElement alloc] initWithAccessibilityContainer:self]; | |
element.isAccessibilityElement = YES; | |
CGRect segmentFrame = CGRectMake(i * segmentWidth, 0, segmentWidth, segmentHeight); | |
element.accessibilityFrame = [self.window convertRect:segmentFrame fromView:self]; | |
UIAccessibilityTraits traits = UIAccessibilityTraitAllowsDirectInteraction; | |
if (i == [self selectedSegmentIndex]) | |
{ | |
traits = traits | UIAccessibilityTraitSelected; | |
} | |
if (enabled == NO) | |
{ | |
traits = traits | UIAccessibilityTraitNotEnabled; | |
} | |
element.accessibilityLabel = [NSString stringWithFormat:NSLocalizedString(@"%@. Tab %d, of %d.", nil), string, i+1, numberOfSegments]; | |
// Add the accessibility element. | |
element.accessibilityTraits = traits; | |
[_accessibilityElements addObject:element]; | |
[element release]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment