/FSCalendar

A powerful ios calendar view with subtitle and smooth scrolling supported,written in Objective-C

Primary LanguageObjective-CMIT LicenseMIT

fscalendar

Version License Platform

fscalendar---takealook

Installation

  • Using cocoapods:pod 'FSCalendar'
  • Manually: Unzip downloaded zip file, drag all files under FSCalendar-master/Pod/Classes to your project, make sure copy items if needed is checked.
#import "FSCalendar.h"

Setup

Use Interface Builder (Recommended)

  1. Drag an UIView object to ViewController Scene, change the Custom Class to FSCalendar
  2. After adjust the position and frame, link the dataSource and delegate to the ViewController
  3. Implement FSCalendarDataSource and FSCalendarDelegate in ViewController.m

Use code

@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;

Or swift

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

More usage

If you want FSCalendar to scroll vertically

  • Objective - c
_calendar.flow = FSCalendarFlowVertical;
  • Swift
calendar.flow = .Vertical 

fscalendar-vertical

If you want FSCalendar to scroll horizontally (Default)

  • Objective - c
_calendar.flow = FSCalendarFlowHorizontal; // By default
  • Swift
calendar.flow = .Horizontal 

fscalendar-horizontal

If you want FSCalendar to use Monday as the first column (or any other weekday)

_calendar.firstWeekday = 2; 

fscalendar---monday

The date format of header can be customized

_calendar.appearance.headerDateFormat = @"MMM yy";

fscalendar---headerformat

You can define the appearance

_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];

fscalendar---colors

The day shape doesn't have to be a circle

  • Objective - c
_calendar.appearance.cellStyle = FSCalendarCellStyleRectangle;
  • Swift
calendar.appearance.cellStyle = .Rectangle

fscalendar---rectangle

FSCalendar can show subtitle for each day

// FSCalendarDataSource
- (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date
{
    return yourSubtitle;
}

fscalendar---subtitle2
fscalendar---subtitle1

And event dot for some days

// FSCalendarDataSource
- (BOOL)calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date
{
    return shouldShowEventDot;
}

Or image for some days

// FSCalendarDataSource
- (UIImage *)calendar:(FSCalendar *)calendar imageForDate:(NSDate *)date
{
    return anyImage;
}

fscalendar---image

There are left and right boundaries

// FSCalendarDataSource
- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar
{
    return yourMinimumDate;
}

- (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar
{
    return yourMaximumDate;
}

You can do something when a date is selected

// FSCalendarDelegate
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date
{
    // Do something
}

You can prevent it from being selected

// FSCalendarDelegate
- (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date
{
    if ([dateShouldNotBeSelected]) {
        return NO;
    }
    return YES;
}

You will get notified when FSCalendar changes the month

- (void)calendarCurrentMonthDidChange:(FSCalendar *)calendar
{
    // Do something
}

FSCalendar can be used on iPad.

fscalendar-ipad

Requirements

ios 7.0

Known issues

  • 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;
  • Can we hide this? fscalendar---headeralpha
_calendar.appearance.headerMinimumDissolvedAlpha = 0.0;

License

FSCalendar is available under the MIT license. See the LICENSE file for more info.

Support

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

Contact

  • email: f33chobits@gmail.com
  • skype: wenchao.ding

Donate