Skip to content

Instantly share code, notes, and snippets.

@justin
Created January 10, 2012 00:54
Show Gist options
  • Save justin/1586076 to your computer and use it in GitHub Desktop.
Save justin/1586076 to your computer and use it in GitHub Desktop.
UIAccessibilityElement Example
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