Go to file
WenchaoD 2b52d05f0e Clean other examples 2016-09-18 18:12:54 +08:00
DynamicTodayExtensionExample Clean other examples 2016-09-18 18:12:54 +08:00
Example Deprecate redundant helpers 2016-09-18 17:54:46 +08:00
FSCalendar Deprecate redundant helpers 2016-09-18 17:54:46 +08:00
SwiftExample Clean other examples 2016-09-18 18:12:54 +08:00
TodayExtensionExample/TodayExtensionExample Clean other examples 2016-09-18 18:12:54 +08:00
.gitignore Add event colors in delegate appearance 2016-03-24 21:36:14 +08:00
.travis.yml Move travis icon a bit 2016-03-26 13:50:19 +08:00
FSCalendar.podspec Add today extensions 2016-09-10 10:14:09 +08:00
LICENSE Update LICENSE 2016-03-29 16:42:54 +08:00
MOREUSAGE.md Add today extensions 2016-09-10 10:14:09 +08:00
README.md Deprecate redundant helpers 2016-09-18 17:54:46 +08:00

README.md

logo

Travis Version Platform Swift2 compatible Carthage compatible

Updates

To get the iOS7 compatibility, You need to include NSCalendarExtension into your project.

中文介绍

QQ交流群: 323861692

Table of contents

Screenshots

iPhone

fscalendar

iPad

fscalendar-ipad

Working with AutoLayout and Orientation

fscalendar-scope-orientation-autolayout

Hide placeholder dates

fscalendar-showsplaceholder

Scope gesture

scopegesture

FSCalendar doesn't change frame or the constraint by itself, see Adjusts frame dynamicly

Today Extension

1
2

Installation

CocoaPods:

  • For iOS8+: 👍
use_frameworks!
pod 'FSCalendar'
  • For iOS7+:
pod 'FSCalendar'

To get the iOS7-compatibility, you will also need to include NSCalendarExtension into your project.

  • Alternatively to give it a test run, run the command:
pod try FSCalendar

Carthage:

  • For iOS8+
github "WenchaoD/FSCalendar"

Manually:

  • Drag all files under FSCalendar folder into your project. 👍

Support IBInspectable / IBDesignable

Only the methods marked "👍" support IBInspectable / IBDesignable feature. Have fun with Interface builder

Setup

Use Interface Builder

  1. Drag an UIView object to ViewController Scene
  2. Change the Custom Class to FSCalendar
  3. Link dataSource and delegate to the ViewController

fscalendar-ib

  1. Finally, you should implement FSCalendarDataSource and FSCalendarDelegate in ViewController.m

Or use code

@property (weak , nonatomic) FSCalendar *calendar;
// In loadView(Recommended) 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

Warning

FSCalendar doesn't change frame by itself, Please implement

  • For autoLayout
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
    _calendarHeightConstraint.constant = CGRectGetHeight(bounds);
    [self.view layoutIfNeeded];
}
  • For manual layout
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
    calendar.frame = (CGRect){calendar.frame.origin,bounds.size};
}

Roll with Interface Builder

fscalendar - ibdesignable

Pre-knowledge

How to create NSDate object

  • By NSCalendar.
self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];

Then:

NSDate *date = [gregorian dateWithEra:1 year:2016 month:9 day:10 hour:0 minute:0 second:0 nanosecond:0];
// 2016-09-10 00:00:00
  • Or by NSDateFormatter
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateFormat = @"yyyy-MM-dd";

Then:

NSDate *date = [self.formatter dateFromString:@"2016-09-10"];

How to print out NSDate object

  • Use NSDateFormatter
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateFormat = @"yyyy/MM/dd";
NSString *string = [self.formatter stringFromDate:date];
NSLog(@"Date is %@", string);

How to manipulate NSDate with NSCalendar

self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
  • Get next month
NSDate *nextMonth = [self.gregorain dateByAddingUnit:NSCalendarUnitMonth value:1 toDate:date options:0];
  • Get next day
NSDate *nextDay = [self.gregorain dateByAddingUnit:NSCalendarUnitDay value:1 toDate:date options:0];
  • Is date in today/tomorrow/yesterday/weekend
BOOL isToday = [self.gregorian isDateInToday:date];
BOOL isYesterday = [self.gregorian isDateInYesterday:date];
BOOL isTomorrow = [self.gregorian isDateInTomorrow:date];
BOOL isWeekend = [self.gregorian isDateInWeekend:date];
  • Compare two dates

BOOL sameDay = [self.gregorian isDate:date1 inSameDayAsDate:date2];

[self.gregorian compareDate:date1 toDate:date2 toUnitGranularity:unit];
// return NSOrderAscending/NSOrderSame/NSOrderDecending

BOOL inSameUnit = [self.gregorian isDate:date1 equalToDate:date2 toUnitGranularity:unit];
// Same in given unit. e.g. NSCalendarUnitMonth means in same month


These features of NSCalendar is introduced in iOS8, to use them in lower version, pay attention to NSCalendarExtension

Support me via paypal


打赏支持

Communications

  • If you found a bug with certain steps to reproduce, open an issue.
  • If you need help about your code, use stackoverflow and tag fscalendar
  • If you want to contribute, submit a pull request. Make sure to follow Coding Guidelines for Cocoa

# Contact

License

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