Skip to content

Commit

Permalink
Make calendar accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
klazuka committed Jun 22, 2012
1 parent b2e164c commit 50b02e2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ In order to use Kal in your application, you will need to provide an implementat
Release Notes
-------------

**June 21, 2012**

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.

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".

**July 9, 2010**

This is the iOS 4.0 / iPhone4 release. New features include:
Expand Down
1 change: 1 addition & 0 deletions src/KalMonthView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@interface KalMonthView : UIView
{
NSUInteger numWeeks;
NSDateFormatter *tileAccessibilityFormatter;
}

@property (nonatomic) NSUInteger numWeeks;
Expand Down
22 changes: 22 additions & 0 deletions src/KalMonthView.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ @implementation KalMonthView
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
tileAccessibilityFormatter = [[NSDateFormatter alloc] init];
[tileAccessibilityFormatter setDateFormat:@"EEEE, MMMM d"];
self.opaque = NO;
self.clipsToBounds = YES;
for (int i=0; i<6; i++) {
Expand Down Expand Up @@ -94,7 +96,27 @@ - (void)sizeToFit
- (void)markTilesForDates:(NSArray *)dates
{
for (KalTileView *tile in self.subviews)
{
tile.marked = [dates containsObject:tile.date];
NSString *dayString = [tileAccessibilityFormatter stringFromDate:[tile.date NSDate]];
if (dayString) {
NSMutableString *helperText = [[[NSMutableString alloc] initWithCapacity:128] autorelease];
if ([tile.date isToday])
[helperText appendFormat:@"%@ ", NSLocalizedString(@"Today", @"Accessibility text for a day tile that represents today")];
[helperText appendString:dayString];
if (tile.marked)
[helperText appendFormat:@". %@", NSLocalizedString(@"Marked", @"Accessibility text for a day tile which is marked with a small dot")];
[tile setAccessibilityLabel:helperText];
}
}
}

#pragma mark -

- (void)dealloc
{
[tileAccessibilityFormatter release];
[super dealloc];
}

@end
2 changes: 2 additions & 0 deletions src/KalTileView.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ - (id)initWithFrame:(CGRect)frame
self.backgroundColor = [UIColor clearColor];
self.clipsToBounds = NO;
origin = frame.origin;
[self setIsAccessibilityElement:YES];
[self setAccessibilityTraits:UIAccessibilityTraitButton];
[self resetState];
}
return self;
Expand Down
4 changes: 4 additions & 0 deletions src/KalView.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ - (void)addSubviewsToHeaderView:(UIView *)headerView
kChangeMonthButtonWidth,
kChangeMonthButtonHeight);
UIButton *previousMonthButton = [[UIButton alloc] initWithFrame:previousMonthButtonFrame];
[previousMonthButton setAccessibilityLabel:NSLocalizedString(@"Previous month", nil)];
[previousMonthButton setImage:[UIImage imageNamed:@"Kal.bundle/kal_left_arrow.png"] forState:UIControlStateNormal];
previousMonthButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
previousMonthButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
Expand Down Expand Up @@ -116,6 +117,7 @@ - (void)addSubviewsToHeaderView:(UIView *)headerView
kChangeMonthButtonWidth,
kChangeMonthButtonHeight);
UIButton *nextMonthButton = [[UIButton alloc] initWithFrame:nextMonthButtonFrame];
[nextMonthButton setAccessibilityLabel:NSLocalizedString(@"Next month", nil)];
[nextMonthButton setImage:[UIImage imageNamed:@"Kal.bundle/kal_right_arrow.png"] forState:UIControlStateNormal];
nextMonthButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
nextMonthButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
Expand All @@ -125,6 +127,7 @@ - (void)addSubviewsToHeaderView:(UIView *)headerView

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

0 comments on commit 50b02e2

Please sign in to comment.