diff --git a/Examples/NativeCal/Classes/NativeCalAppDelegate.m b/Examples/NativeCal/Classes/NativeCalAppDelegate.m index 08912cb..12fbbc6 100644 --- a/Examples/NativeCal/Classes/NativeCalAppDelegate.m +++ b/Examples/NativeCal/Classes/NativeCalAppDelegate.m @@ -23,7 +23,8 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application * If your application requires an arbitrary starting date, use -[KalViewController initWithSelectedDate:] * instead of -[KalViewController init]. */ - kal = [[KalViewController alloc] init]; + NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"zh-HK"] autorelease]; + kal = [[KalViewController alloc] initWithLocale:locale]; kal.title = @"NativeCal"; /* diff --git a/src/KalGridView.m b/src/KalGridView.m index 798d73e..c5e3f8f 100644 --- a/src/KalGridView.m +++ b/src/KalGridView.m @@ -49,8 +49,8 @@ - (id)initWithFrame:(CGRect)frame logic:(KalLogic *)theLogic delegate:(id +#import "KalLogic.h" + @class KalTileView, KalDate; @interface KalMonthView : UIView @@ -16,6 +18,8 @@ @property (nonatomic) NSUInteger numWeeks; - (id)initWithFrame:(CGRect)rect; // designated initializer +- (id)initWithFrame:(CGRect)rect logic:(KalLogic *)logic; + - (void)showDates:(NSArray *)mainDates leadingAdjacentDates:(NSArray *)leadingAdjacentDates trailingAdjacentDates:(NSArray *)trailingAdjacentDates; - (KalTileView *)firstTileOfMonth; - (KalTileView *)tileForDate:(KalDate *)date; diff --git a/src/KalMonthView.m b/src/KalMonthView.m index 8c9989b..4ab97fe 100644 --- a/src/KalMonthView.m +++ b/src/KalMonthView.m @@ -16,21 +16,28 @@ @implementation KalMonthView @synthesize numWeeks; -- (id)initWithFrame:(CGRect)frame +- (id)initWithFrame:(CGRect)rect logic:(KalLogic *)logic { - 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++) { - for (int j=0; j<7; j++) { - CGRect r = CGRectMake(j*kTileSize.width, i*kTileSize.height, kTileSize.width, kTileSize.height); - [self addSubview:[[[KalTileView alloc] initWithFrame:r] autorelease]]; - } + if ((self = [super initWithFrame:rect])) { + NSString *format = [NSDateFormatter dateFormatFromTemplate:@"EEEE, MMM d" options:0 locale:logic.locale]; + tileAccessibilityFormatter = [[NSDateFormatter alloc] init]; + [tileAccessibilityFormatter setDateFormat:format]; + [tileAccessibilityFormatter setLocale:logic.locale]; + self.opaque = NO; + self.clipsToBounds = YES; + for (int i=0; i<6; i++) { + for (int j=0; j<7; j++) { + CGRect r = CGRectMake(j*kTileSize.width, i*kTileSize.height, kTileSize.width, kTileSize.height); + [self addSubview:[[[KalTileView alloc] initWithFrame:r] autorelease]]; + } + } } - } - return self; + return self; +} + +- (id)initWithFrame:(CGRect)frame +{ + return [self initWithFrame:frame logic:nil]; } - (void)showDates:(NSArray *)mainDates leadingAdjacentDates:(NSArray *)leadingAdjacentDates trailingAdjacentDates:(NSArray *)trailingAdjacentDates diff --git a/src/KalView.m b/src/KalView.m index def1dcb..e387b81 100644 --- a/src/KalView.m +++ b/src/KalView.m @@ -126,8 +126,11 @@ - (void)addSubviewsToHeaderView:(UIView *)headerView [nextMonthButton release]; // 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]; + NSDateFormatter *df = [[NSDateFormatter alloc] init]; + [df setLocale:logic.locale]; + NSArray *weekdayNames = [df shortWeekdaySymbols]; + NSArray *fullWeekdayNames = [df standaloneWeekdaySymbols]; + [df release]; NSUInteger firstWeekday = [[NSCalendar currentCalendar] firstWeekday]; NSUInteger i = firstWeekday - 1; for (CGFloat xOffset = 0.f; xOffset < headerView.width; xOffset += 46.f, i = (i+1)%7) { diff --git a/src/KalViewController.h b/src/KalViewController.h index ba9ddb9..a3d8174 100644 --- a/src/KalViewController.h +++ b/src/KalViewController.h @@ -35,6 +35,10 @@ @property (nonatomic, retain, readonly) NSDate *selectedDate; - (id)initWithSelectedDate:(NSDate *)selectedDate; // designated initializer. When the calendar is first displayed to the user, the month that contains 'selectedDate' will be shown and the corresponding tile for 'selectedDate' will be automatically selected. + +- (id)initWithSelectedDate:(NSDate *)date locale:(NSLocale *)locale; +- (id)initWithLocale:(NSLocale *)locale; + - (void)reloadData; // If you change the KalDataSource after the KalViewController has already been displayed to the user, you must call this method in order for the view to reflect the new data. - (void)showAndSelectDate:(NSDate *)date; // Updates the state of the calendar to display the specified date's month and selects the tile for that date. diff --git a/src/KalViewController.m b/src/KalViewController.m index 62245b8..2a431c5 100644 --- a/src/KalViewController.m +++ b/src/KalViewController.m @@ -40,16 +40,26 @@ @implementation KalViewController @synthesize dataSource, delegate, initialDate, selectedDate; +- (id)initWithSelectedDate:(NSDate *)date locale:(NSLocale *)locale +{ + if ((self = [super init])) { + logic = [[KalLogic alloc] initForDate:date locale:locale]; + self.initialDate = date; + self.selectedDate = date; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(significantTimeChangeOccurred) name:UIApplicationSignificantTimeChangeNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData) name:KalDataSourceChangedNotification object:nil]; + } + return self; +} + - (id)initWithSelectedDate:(NSDate *)date { - if ((self = [super init])) { - logic = [[KalLogic alloc] initForDate:date]; - self.initialDate = date; - self.selectedDate = date; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(significantTimeChangeOccurred) name:UIApplicationSignificantTimeChangeNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData) name:KalDataSourceChangedNotification object:nil]; - } - return self; + return [self initWithSelectedDate:date locale:nil]; +} + +- (id)initWithLocale:(NSLocale *)locale +{ + return [self initWithSelectedDate:[NSDate date] locale:locale]; } - (id)init