Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #184 from mikevpark/master

Adding accessibility to the calendar grid.
  • Loading branch information...
commit 0f83a6a8cd61f0a3dca9b7c840a79be5a2c2efb6 2 parents cedd121 + 0917fe4
Devin Ross authored
Showing with 72 additions and 2 deletions.
  1. +72 −2 src/TapkuLibrary/TKCalendarMonthView.m
View
74 src/TapkuLibrary/TKCalendarMonthView.m
@@ -142,6 +142,7 @@ @interface TKCalendarMonthTiles : UIView {
BOOL startOnSunday;
}
@property (strong,nonatomic) NSDate *monthDate;
+@property (nonatomic, strong) NSMutableArray *accessibleElements;
- (id) initWithMonth:(NSDate*)date marks:(NSArray*)marks startDayOnSunday:(BOOL)sunday;
- (void) setTarget:(id)target action:(SEL)action;
@@ -166,6 +167,42 @@ @interface TKCalendarMonthTiles (private)
@implementation TKCalendarMonthTiles
@synthesize monthDate;
+#pragma mark - Accessibility Container methods
+
+- (NSArray *)accessibleElements
+{
+ if (_accessibleElements != nil)
+ {
+ return _accessibleElements;
+ }
+
+ _accessibleElements = [[NSMutableArray alloc] init];
+
+ return _accessibleElements;
+}
+
+//The container itself is not accessible
+- (BOOL)isAccessibilityElement
+{
+ return NO;
+}
+
+- (NSInteger)accessibilityElementCount
+{
+ return [[self accessibleElements] count];
+}
+
+- (id)accessibilityElementAtIndex:(NSInteger)index
+{
+ return [[self accessibleElements] objectAtIndex:index];
+}
+
+- (NSInteger)indexOfAccessibilityElement:(id)element
+{
+ return [[self accessibleElements] indexOfObject:element];
+}
+
+#pragma mark - Init Methods
+ (NSArray*) rangeOfDatesInMonthGrid:(NSDate*)date startOnSunday:(BOOL)sunday{
@@ -303,7 +340,12 @@ - (id) initWithMonth:(NSDate*)date marks:(NSArray*)markArray startDayOnSunday:(B
[self.selectedImageView addSubview:self.currentDay];
[self.selectedImageView addSubview:self.dot];
self.multipleTouchEnabled = NO;
-
+
+ //Set Accessibility
+ self.selectedImageView.isAccessibilityElement = YES;
+ self.selectedImageView.accessibilityTraits = UIAccessibilityTraitButton;
+ self.selectedImageView.accessibilityLabel = [NSString stringWithFormat:@"Day %@, %@", self.currentDay.text, self.dot ? @"Activities" : @"No Activities"];
+
return self;
}
@@ -341,7 +383,15 @@ - (void) drawTileInRect:(CGRect)r day:(int)day mark:(BOOL)mark font:(UIFont*)f1
alignment: UITextAlignmentCenter];
}
-
+ //Set Accessibility
+ UIAccessibilityElement *tileElement = [[UIAccessibilityElement alloc] initWithAccessibilityContainer:self];
+ tileElement.accessibilityFrame = [self convertRect:r toView:nil];
+ tileElement.accessibilityLabel = str;
+ tileElement.accessibilityValue = mark ? @"Activities" : @"No Activities";
+ tileElement.accessibilityTraits = UIAccessibilityTraitUpdatesFrequently;
+
+ [_accessibleElements addObject:tileElement];
+
}
- (void) drawRect:(CGRect)rect {
@@ -717,6 +767,24 @@ - (id) initWithSundayAsFirst:(BOOL)s{
for(NSString *s in ar){
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(46 * i, 29, 46, 15)];
[self addSubview:label];
+
+ //Added Accessibility Labels
+ if ([s isEqualToString:@"Sun"]) {
+ label.accessibilityLabel = @"Sunday";
+ } else if ([s isEqualToString:@"Mon"]) {
+ label.accessibilityLabel = @"Monday";
+ } else if ([s isEqualToString:@"Tue"]) {
+ label.accessibilityLabel = @"Tuesday";
+ } else if ([s isEqualToString:@"Wed"]) {
+ label.accessibilityLabel = @"Wednesday";
+ } else if ([s isEqualToString:@"Thu"]) {
+ label.accessibilityLabel = @"Thursday";
+ } else if ([s isEqualToString:@"Fri"]) {
+ label.accessibilityLabel = @"Friday";
+ } else if ([s isEqualToString:@"Sat"]) {
+ label.accessibilityLabel = @"Saturday";
+ }
+
label.text = s;
label.textAlignment = UITextAlignmentCenter;
label.shadowColor = [UIColor whiteColor];
@@ -973,6 +1041,7 @@ - (UIButton *) leftArrow{
if(leftArrow==nil){
leftArrow = [UIButton buttonWithType:UIButtonTypeCustom];
leftArrow.tag = 0;
+ leftArrow.accessibilityLabel = @"Previous Month";
[leftArrow addTarget:self action:@selector(changeMonth:) forControlEvents:UIControlEventTouchUpInside];
[leftArrow setImage:[UIImage imageNamedTK:@"TapkuLibrary.bundle/Images/calendar/Month Calendar Left Arrow"] forState:0];
leftArrow.frame = CGRectMake(0, 0, 48, 38);
@@ -983,6 +1052,7 @@ - (UIButton *) rightArrow{
if(rightArrow==nil){
rightArrow = [UIButton buttonWithType:UIButtonTypeCustom];
rightArrow.tag = 1;
+ rightArrow.accessibilityLabel = @"Next Month";
[rightArrow addTarget:self action:@selector(changeMonth:) forControlEvents:UIControlEventTouchUpInside];
rightArrow.frame = CGRectMake(320-45, 0, 48, 38);
[rightArrow setImage:[UIImage imageNamedTK:@"TapkuLibrary.bundle/Images/calendar/Month Calendar Right Arrow"] forState:0];
Please sign in to comment.
Something went wrong with that request. Please try again.