|
|
||
|---|---|---|
| DynamicTodayExtensionExample | ||
| Example | ||
| FSCalendar | ||
| SwiftExample | ||
| TodayExtensionExample/TodayExtensionExample | ||
| .gitignore | ||
| .travis.yml | ||
| FSCalendar.podspec | ||
| LICENSE | ||
| MOREUSAGE.md | ||
| README.md | ||
README.md
Updates
To get the iOS7 compatibility, You need to include NSCalendarExtension into your project.
中文介绍
Table of contents
Screenshots
iPhone
iPad
Working with AutoLayout and Orientation
Hide placeholder dates
Scope gesture
FSCalendar doesn't change frame or the constraint by itself, see Adjusts frame dynamicly
Today Extension
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
FSCalendarfolder into your project. 👍
Support IBInspectable / IBDesignable
Only the methods marked "👍" support IBInspectable / IBDesignable feature. Have fun with Interface builder
Setup
Use Interface Builder
- Drag an UIView object to ViewController Scene
- Change the
Custom ClasstoFSCalendar - Link
dataSourceanddelegateto the ViewController
- Finally, you should implement
FSCalendarDataSourceandFSCalendarDelegatein 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
- To use
FSCalendarin 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
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
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
打赏支持
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
License
FSCalendar is available under the MIT license. See the LICENSE file for more info.









