ios-calendar is a stylable month calendar view for use in iPhone applications.
It has two branches:
three20
uses Three20 framework for stylingmaster
allows you customize it without using Three20. It uses Nimbus, so it’s good idea to use Nimbus CSS for styling.
Note that README right now is a bit out of date and applies mostly to three20
branch, however the demo and tests are up-to-date.
While there are existing implementations (Kal and TKCalendarMonthView
from Tapku Library, they are quite limited. In particular they both replicate styling and functionality of iPhone Calendar app and there is basically no easy way to adjust them. In addition to this – only portrait view is supported in them.
ios-calenar was developed to solve aforementioned problems. It’s default design is heavily inspired by MoMa iPhone app.
I maintain a list of apps using ios-calendar, feel free to add your app to it.
While not elegant at all, currently the best method to add ios-calendar to your project is just to drop its source code in it (from “Calendar” group).
It is possible to use it as dependency, but only when your project doesn’t itself use Three20. Otherwise build results in XCode crash. I’m looking for suggestions on how better to resolve this issue.
XCode project on GitHub contains sample target – CalendarDemo. Here are main highlights:
#import "CalendarDemoViewController.h"
#import <Three20UICommon/Three20UICommon+Additions.h>
@implementation CalendarDemoViewController
@synthesize calendarView;
- (void) loadView {
[super loadView];
self.calendarView = [[CXCalendarView new] autorelease];
[self.view addSubview: self.calendarView];
self.calendarView.frame = self.view.bounds;
self.calendarView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.calendarView.selectedDate = [NSDate date];
self.calendarView.delegate = self;
}
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation {
return YES;
}
#pragma mark CXCalendarViewDelegate
- (void) calendarView: (CXCalendarView *) calendarView
didSelectDate: (NSDate *) date {
NSLog(@"Selected date: %@", date);
TTAlert([NSString stringWithFormat: @"Selected date: %@", date]);
}
@end
There is one very important thing to do in app delegate – set up Three20 styling. There is sample stylesheet (inspired by MoMA) – TestStyleSheet
.
#import "CalendarDemoAppDelegate.h"
#import "TestStyleSheet.h"
#import "CalendarDemoViewController.h"
@implementation CalendarDemoAppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;
- (BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions {
[TTStyleSheet setGlobalStyleSheet: [[TestStyleSheet new] autorelease]];
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[CalendarDemoViewController alloc] init];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
@end
Here’s default stylesheet for you to study:
#import "TestStyleSheet.h"
@implementation TestStyleSheet
- (TTStyle *) calendarCellStyle: (UIControlState) state {
if (state & UIControlStateDisabled) {
return [TTTextStyle styleWithColor: [UIColor clearColor] next: nil];
}
if (state & UIControlStateSelected) {
return [TTSolidFillStyle styleWithColor: [UIColor grayColor] next:
[TTTextStyle styleWithColor: [UIColor whiteColor] next: nil]];
}
return [TTTextStyle styleWithColor: [UIColor grayColor] next: nil];
}
- (TTStyle *) calendarMonthBarStyle {
return
[TTLinearGradientFillStyle styleWithColor1: RGBCOLOR(188, 200, 215)
color2: RGBCOLOR(125, 150, 179) next:
[TTFourBorderStyle styleWithTop: RGBCOLOR(213, 221, 230)
right: nil
bottom: RGBCOLOR(57, 70, 84)
left: nil
width: 1 next: nil]];
}
- (TTStyle *) calendarMonthBackButton: (UIControlState) state {
return
[TTTextStyle styleWithFont: [UIFont systemFontOfSize: [UIFont buttonFontSize]]
color: [UIColor whiteColor]
shadowColor: [UIColor grayColor]
shadowOffset: CGSizeMake(0, 1) next: nil];
}
- (TTStyle *) calendarMonthForwardButton: (UIControlState) state {
return
[TTTextStyle styleWithFont: [UIFont systemFontOfSize: [UIFont buttonFontSize]]
color: [UIColor whiteColor]
shadowColor: [UIColor grayColor]
shadowOffset: CGSizeMake(0, 1) next: nil];
}
- (TTStyle *) calendarMonthLabelStyle {
return
[TTTextStyle styleWithFont: [UIFont systemFontOfSize: [UIFont buttonFontSize]]
color: [UIColor whiteColor]
shadowColor: [UIColor grayColor]
shadowOffset: CGSizeMake(0, 1) next: nil];
}
- (TTStyle *) calendarGridViewStyle {
return [TTSolidFillStyle styleWithColor: [UIColor whiteColor] next: nil];
}
@end
Code is distributed under MIT license, attribution is appreciated:
Copyright (C) 2011 by Componentix http://www.componentix.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.