Skip to content

Instantly share code, notes, and snippets.

@futuretap
Created October 27, 2015 22:57
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 futuretap/81d3f46fe05ed68d0c87 to your computer and use it in GitHub Desktop.
Save futuretap/81d3f46fe05ed68d0c87 to your computer and use it in GitHub Desktop.
Workaround to make UISegmentedControl with images accessible. See http://openradar.appspot.com/radar?id=118413
//
// UISegmentedControl+Accessibility.m
//
// Created by Ortwin Gentz on 30.05.14.
// Copyright (c) 2014 FutureTap. All rights reserved.
//
@implementation UISegmentedControl (Accessibility)
// Use these convenience setters for easy customization in IB using user defined runtime attributes
- (void)setAccessibilityLabel0:(NSString *)accessibilityLabel {
[self setAccessibilityLabel:accessibilityLabel forItem:0];
}
- (void)setAccessibilityLabel1:(NSString *)accessibilityLabel {
[self setAccessibilityLabel:accessibilityLabel forItem:1];
}
- (void)setAccessibilityLabel2:(NSString *)accessibilityLabel {
[self setAccessibilityLabel:accessibilityLabel forItem:2];
}
- (void)setAccessibilityLabel3:(NSString *)accessibilityLabel {
[self setAccessibilityLabel:accessibilityLabel forItem:3];
}
- (void)setAccessibilityLabel:(NSString *)accessibilityLabel forItem:(NSUInteger)item {
if (item >= self.numberOfSegments) {
return;
}
NSUInteger reversedItem = self.numberOfSegments - item - 1;
((UIImageView*)self.subviews[reversedItem]).accessibilityLabel = accessibilityLabel;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment