JTCalendar
JTCalendar is a calendar control for iOS easily customizable.
JTCalendar 是一个很容易定制的日历的控件。
Usage
You have to create two views in your UIViewController.
你需要在你的UIViewController创建出两个view。
The first view is JTCalendarMenuView
, it represents the months.
第一个view是JTCalendarMenuView,他代表着月份。
The second view is JTCalendarContentView
, the calendar itself.
第二个view是JTCalendarContentView,这个是日历本身。
Your UIViewController must implement JTCalendarDataSource
你的UIViewController 必须实现JTCalendarDataSource代理。
#import <UIKit/UIKit.h> #import "JTCalendar.h" @interface ViewController : UIViewController<JTCalendarDataSource> @property (weak, nonatomic) IBOutlet JTCalendarMenuView *calendarMenuView; @property (weak, nonatomic) IBOutlet JTCalendarContentView *calendarContentView; @property (strong, nonatomic) JTCalendar *calendar; @end
JTCalendar
is used to coordinate calendarMenuView
and calendarContentView
.
JTCalendar
是用来定位calendarMenuView与
calendarContentView的。
@implementation ViewController
- (void)viewDidLoad { [super viewDidLoad]; self.calendar = [JTCalendar new]; [self.calendar setMenuMonthsView:self.calendarMenuView]; [self.calendar setContentView:self.calendarContentView]; [self.calendar setDataSource:self]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self.calendar reloadData]; // Must be call in viewDidAppear } - (BOOL)calendarHaveEvent:(JTCalendar *)calendar date:(NSDate *)date { return NO; } - (void)calendarDidDateSelected:(JTCalendar *)calendar date:(NSDate *)date { NSLog(@"%@", date); } @end
切换到week
If you want see just one week at time you can switch when you want between the weekMode.
如果你只想看一周的时间,你可以切换到weekMode模式
self.calendar.calendarAppearance.isWeekMode = YES;
[self.calendar reloadAppearance];
注意
When you change the mode, it doesn't change the height of calendarContentView
, you have to do it yourself. See the project in example for more details.
当你切换样式时,他并没有改变calendarContentView的高度,你需要自己手动设置。你可以在项目中找到实现细节。
自定义设计
You have a lot of options available for personnalize the design. Check the JTCalendarAppearance.h
file for see all options.
你有这很多很多的选项来定制设计。你可以再JTCalendarAppearance.h文件中找到这些配置选项。
self.calendar.calendarAppearance.calendar.firstWeekday = 2; // Monday self.calendar.calendarAppearance.ratioContentMenu = 1.; self.calendar.calendarAppearance.menuMonthTextColor = [UIColor whiteColor]; self.calendar.calendarAppearance.dayCircleColorSelected = [UIColor blueColor]; self.calendar.calendarAppearance.dayTextColorSelected = [UIColor whiteColor]; [self.calendar reloadAppearance];
推荐用法
The call to reloadAppearance
is expensive, reloadAppearance
is call by setMenuMonthsView
andsetContentView
.
调用reloadAppearance
开销很大,setMenuMonthsView
与andsetContentView会调用
reloadAppearance
方法
For better performance define the appearance just after instanciate JTCalendar
.
BAD example:
self.calendar = [JTCalendar new];
[self.calendar setMenuMonthsView:self.calendarMenuView]; [self.calendar setContentView:self.calendarContentView]; [self.calendar setDataSource:self]; self.calendar.calendarAppearance.calendar.firstWeekday = 2; // Monday self.calendar.calendarAppearance.ratioContentMenu = 1.; self.calendar.calendarAppearance.menuMonthTextColor = [UIColor whiteColor]; self.calendar.calendarAppearance.dayCircleColorSelected = [UIColor blueColor]; self.calendar.calendarAppearance.dayTextColorSelected = [UIColor whiteColor]; [self.calendar reloadAppearance]; // You have to call reloadAppearance
GOOD example:
self.calendar = [JTCalendar new];
self.calendar.calendarAppearance.calendar.firstWeekday = 2; // Monday self.calendar.calendarAppearance.ratioContentMenu = 1.; self.calendar.calendarAppearance.menuMonthTextColor = [UIColor whiteColor]; self.calendar.calendarAppearance.dayCircleColorSelected = [UIColor blueColor]; self.calendar.calendarAppearance.dayTextColorSelected = [UIColor whiteColor]; [self.calendar setMenuMonthsView:self.calendarMenuView]; [self.calendar setContentView:self.calendarContentView]; [self.calendar setDataSource:self]; // You don't have to call reloadAppearance
You may also want to open your calendar on a specific date, by defaut it's [NSDate date].
你也许想在打开日历的时候定位到指定的日期,默认值是[NSDate date]
[self.calendar setCurrentDate:myDate];