- For iOS8+: 👍
use_frameworks!
pod 'FSCalendar'
- For iOS7+:
pod 'FSCalendar'
- For iOS8+
github "WenchaoIOS/FSCalendar"
- Drag all files under
FSCalendar
folder into your project. 👍
Only the methods marked "👍" support IBInspectable / IBDesignable feature. Have fun with Interface builder
- Drag an UIView object to ViewController Scene
- Change the
Custom Class
toFSCalendar
- Link
dataSource
anddelegate
to the ViewController
- Finally, you should implement
FSCalendarDataSource
andFSCalendarDelegate
in ViewController.m
@property (weak , nonatomic) FSCalendar *calendar;
// In loadView or viewDidLoad
FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
calendar.dataSource = self;
calendar.delegate = self;
[self.view addSubview:calendar];
self.calendar = calendar;
- To use
FSCalendar
in swift, you need to Create Bridge Header first.
private weak var calendar: FSCalendar!
// In loadView or viewDidLoad
let calendar = FSCalendar(frame: CGRect(x: 0, y: 0, width: 320, height: 300))
calendar.dataSource = self
calendar.delegate = self
view.addSubview(calendar)
self.calendar = calendar
- Objective - c
_calendar.scrollDirection = FSCalendarScrollDirectionVertical;
- Swift
calendar.scrollDirection = .Vertical
- Objective - c
_calendar.scrollDirection = FSCalendarScrollDirectionHorizontal; // By default
- Swift
calendar.scrollDirection = .Horizontal
- Objective - c
_calendar.scope = FSCalendarScopeWeek;
- Swift
calendar.scope = .Week
- Objective - c
_calendar.scope = FSCalendarScopeMonth; // By default
- Swift
calendar.scope = .Month
_calendar.allowsMultipleSelection = YES;
_calendar.firstWeekday = 2;
_calendar.appearance.headerDateFormat = @"MMM yy";
_calendar.appearance.weekdayTextColor = [UIColor redColor];
_calendar.appearance.headerTitleColor = [UIColor redColor];
_calendar.appearance.eventColor = [UIColor greenColor];
_calendar.appearance.selectionColor = [UIColor blueColor];
_calendar.appearance.todayColor = [UIColor orangeColor];
_calendar.appearance.todaySelectionColor = [UIColor blackColor];
- Objective - c
_calendar.appearance.cellStyle = FSCalendarCellStyleRectangle;
- Swift
calendar.appearance.cellStyle = .Rectangle
- Objective - c
// FSCalendarDataSource
- (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date
{
return yourSubtitle;
}
- Swift
// FSCalendarDataSource
func calendar(calendar: FSCalendar!, subtitleForDate date: NSDate!) -> String! {
return yourSubtitle
}
- Objective - c
// FSCalendarDataSource
- (BOOL)calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date
{
return shouldShowEventDot;
}
- Swift
// FSCalendarDataSource
func calendar(calendar: FSCalendar!, hasEventForDate date: NSDate!) -> Bool {
return shouldShowEventDot
}
- Objective - c
// FSCalendarDataSource
- (UIImage *)calendar:(FSCalendar *)calendar imageForDate:(NSDate *)date
{
return anyImage;
}
- Swift
// FSCalendarDataSource
func calendar(calendar: FSCalendar!, imageForDate date: NSDate!) -> UIImage! {
return anyImage
}
// FSCalendarDataSource
- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar
{
return yourMinimumDate;
}
- (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar
{
return yourMaximumDate;
}
- Objective - c
// FSCalendarDelegate
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date
{
// Do something
}
- Swift
// FSCalendarDelegate
func calendar(calendar: FSCalendar!, didSelectDate date: NSDate!) {
}
- Objective - c
// FSCalendarDelegate
- (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date
{
if ([dateShouldNotBeSelected]) {
return NO;
}
return YES;
}
- Swift
func calendar(calendar: FSCalendar!, shouldSelectDate date: NSDate!) -> Bool {
if dateShouldNotBeSelected {
return false
}
return true
}
- Objective - c
- (void)calendarCurrentMonthDidChange:(FSCalendar *)calendar
{
// Do something
}
- Swift
func calendarCurrentMonthDidChange(calendar: FSCalendar!) {
// Do something
}
fakeSubtitles
andfakedSelectedDay
is only used for preview in Interface Builder
- The title size changed as we change frame size of FSCalendar: Automatically adjusting font size based on frame size is default behavior of FSCalendadr, to disable it:
_calendar.appearance.autoAdjustTitleSize = NO;
_calendar.appearance.titleFont = otherTitleFont;
_calendar.appearance.subtitleFont = otherSubtitleFont;
titleFont
and subtitleFont
would not take any effect if autoAdjustTitleSize
value is YES
- What if I don't need the
today
circle?
_calendar.appearance.todayColor = [UIColor clearColor];
_calendar.appearance.titleTodayColor = _calendar.appearance.titleDefaultColor;
_calendar.appearance.subtitleTodayColor = _calendar.appearance.subtitleDefaultColor;
_calendar.appearance.headerMinimumDissolvedAlpha = 0.0;
FSCalendar is available under the MIT license. See the LICENSE file for more info.
- If FSCalendar cannot meet your requirment, tell me in issues or send your pull requests
- If you like this control and use it in your app, submit your app's link address here.It would be a great support.
- email:
[email protected]
- skype:
wenchao.ding
- Paypal - [email protected]