Skip to content

Commit 50b02e2

Browse files
committed
Make calendar accessible
1 parent b2e164c commit 50b02e2

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

README.markdown

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ In order to use Kal in your application, you will need to provide an implementat
1111
Release Notes
1212
-------------
1313

14+
**June 21, 2012**
15+
16+
Today I added VoiceOver/Accessibility support. Special thanks to Matt Gemmell's [excellent article](http://mattgemmell.com/2010/12/19/accessibility-for-iphone-and-ipad-apps/) on adding accessibility support to your iPhone app. I wish I would have done this a long time ago.
17+
18+
If your app is localized, then you will also want to localize the 4 new accessibility strings that I added in this release: "Previous month", "Next month", "Marked" and "Today".
19+
1420
**July 9, 2010**
1521

1622
This is the iOS 4.0 / iPhone4 release. New features include:

src/KalMonthView.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@interface KalMonthView : UIView
1111
{
1212
NSUInteger numWeeks;
13+
NSDateFormatter *tileAccessibilityFormatter;
1314
}
1415

1516
@property (nonatomic) NSUInteger numWeeks;

src/KalMonthView.m

+22
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ @implementation KalMonthView
1919
- (id)initWithFrame:(CGRect)frame
2020
{
2121
if ((self = [super initWithFrame:frame])) {
22+
tileAccessibilityFormatter = [[NSDateFormatter alloc] init];
23+
[tileAccessibilityFormatter setDateFormat:@"EEEE, MMMM d"];
2224
self.opaque = NO;
2325
self.clipsToBounds = YES;
2426
for (int i=0; i<6; i++) {
@@ -94,7 +96,27 @@ - (void)sizeToFit
9496
- (void)markTilesForDates:(NSArray *)dates
9597
{
9698
for (KalTileView *tile in self.subviews)
99+
{
97100
tile.marked = [dates containsObject:tile.date];
101+
NSString *dayString = [tileAccessibilityFormatter stringFromDate:[tile.date NSDate]];
102+
if (dayString) {
103+
NSMutableString *helperText = [[[NSMutableString alloc] initWithCapacity:128] autorelease];
104+
if ([tile.date isToday])
105+
[helperText appendFormat:@"%@ ", NSLocalizedString(@"Today", @"Accessibility text for a day tile that represents today")];
106+
[helperText appendString:dayString];
107+
if (tile.marked)
108+
[helperText appendFormat:@". %@", NSLocalizedString(@"Marked", @"Accessibility text for a day tile which is marked with a small dot")];
109+
[tile setAccessibilityLabel:helperText];
110+
}
111+
}
112+
}
113+
114+
#pragma mark -
115+
116+
- (void)dealloc
117+
{
118+
[tileAccessibilityFormatter release];
119+
[super dealloc];
98120
}
99121

100122
@end

src/KalTileView.m

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ - (id)initWithFrame:(CGRect)frame
2020
self.backgroundColor = [UIColor clearColor];
2121
self.clipsToBounds = NO;
2222
origin = frame.origin;
23+
[self setIsAccessibilityElement:YES];
24+
[self setAccessibilityTraits:UIAccessibilityTraitButton];
2325
[self resetState];
2426
}
2527
return self;

src/KalView.m

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ - (void)addSubviewsToHeaderView:(UIView *)headerView
8888
kChangeMonthButtonWidth,
8989
kChangeMonthButtonHeight);
9090
UIButton *previousMonthButton = [[UIButton alloc] initWithFrame:previousMonthButtonFrame];
91+
[previousMonthButton setAccessibilityLabel:NSLocalizedString(@"Previous month", nil)];
9192
[previousMonthButton setImage:[UIImage imageNamed:@"Kal.bundle/kal_left_arrow.png"] forState:UIControlStateNormal];
9293
previousMonthButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
9394
previousMonthButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
@@ -116,6 +117,7 @@ - (void)addSubviewsToHeaderView:(UIView *)headerView
116117
kChangeMonthButtonWidth,
117118
kChangeMonthButtonHeight);
118119
UIButton *nextMonthButton = [[UIButton alloc] initWithFrame:nextMonthButtonFrame];
120+
[nextMonthButton setAccessibilityLabel:NSLocalizedString(@"Next month", nil)];
119121
[nextMonthButton setImage:[UIImage imageNamed:@"Kal.bundle/kal_right_arrow.png"] forState:UIControlStateNormal];
120122
nextMonthButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
121123
nextMonthButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
@@ -125,6 +127,7 @@ - (void)addSubviewsToHeaderView:(UIView *)headerView
125127

126128
// Add column labels for each weekday (adjusting based on the current locale's first weekday)
127129
NSArray *weekdayNames = [[[[NSDateFormatter alloc] init] autorelease] shortWeekdaySymbols];
130+
NSArray *fullWeekdayNames = [[[[NSDateFormatter alloc] init] autorelease] standaloneWeekdaySymbols];
128131
NSUInteger firstWeekday = [[NSCalendar currentCalendar] firstWeekday];
129132
NSUInteger i = firstWeekday - 1;
130133
for (CGFloat xOffset = 0.f; xOffset < headerView.width; xOffset += 46.f, i = (i+1)%7) {
@@ -137,6 +140,7 @@ - (void)addSubviewsToHeaderView:(UIView *)headerView
137140
weekdayLabel.shadowColor = [UIColor whiteColor];
138141
weekdayLabel.shadowOffset = CGSizeMake(0.f, 1.f);
139142
weekdayLabel.text = [weekdayNames objectAtIndex:i];
143+
[weekdayLabel setAccessibilityLabel:[fullWeekdayNames objectAtIndex:i]];
140144
[headerView addSubview:weekdayLabel];
141145
[weekdayLabel release];
142146
}

0 commit comments

Comments
 (0)