![Languages](https://img.shields.io/badge/language-objc%20%7C%20swift-FF69B4.svg?style=plastic)
Table of contents
Screenshots
iPhone
![fscalendar](https://cloud.githubusercontent.com/assets/5186464/10262249/4fabae40-69f2-11e5-97ab-afbacd0a3da2.jpg)
iPad
![fscalendar-ipad](https://cloud.githubusercontent.com/assets/5186464/10927681/d2448cb6-82dc-11e5-9d11-f664a06698a7.jpg)
Safe Orientation
![fscalendar-scope-orientation-autolayout](https://cloud.githubusercontent.com/assets/5186464/20325758/ea125e1e-abc0-11e6-9e29-491acbcb0d07.gif)
Today Extension
iOS8/9 | iOS10 |
---|
![today1](https://cloud.githubusercontent.com/assets/5186464/20288375/ed3fba0e-ab0d-11e6-8b15-43d3dc656f22.gif) | ![today2](https://cloud.githubusercontent.com/assets/5186464/20288378/f11e318c-ab0d-11e6-8d1d-9d89b563e9d7.gif) |
Interactive Scope Gesture
DIY support
To customize your own cell, view DIY Example in Example-Swift
or Example-Objc
Swipe-To-Choose
Single-Selection Swipe-To-Choose | Multiple-Selection Swipe-To-Choose | DIY Swipe-To-Choose |
---|
![1](https://cloud.githubusercontent.com/assets/5186464/20257768/cb1905d4-aa86-11e6-9ef7-af76f9caa024.gif) | ![2](https://cloud.githubusercontent.com/assets/5186464/20257826/254070ec-aa87-11e6-81b1-1815453fd464.gif) | ![3](https://cloud.githubusercontent.com/assets/5186464/20257836/2ffa3252-aa87-11e6-8ff9-3b40f5b2307b.gif) |
Achievement of Users
Installation
CocoaPods:
use_frameworks!
target '<Your Target Name>' do
pod 'FSCalendar'
end
target '<Your Target Name>' do
pod 'FSCalendar'
end
NSCalendarExtension is required to get iOS7 compatibility.
Carthage:
github "WenchaoD/FSCalendar"
SPM:
Add dependency:
.package(url: "https://github.com/WenchaoD/FSCalendar.git", from: "2.8.4")
Manually:
- Drag all files under
FSCalendar
folder into your project. 👍
Alternatively to give it a test run, simply press command+u
in Example-Objc
or Example-Swift
and launch the UITest Target.
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](https://cloud.githubusercontent.com/assets/5186464/9488580/a360297e-4c0d-11e5-8548-ee9274e7c4af.jpg)
4、 Finally, implement FSCalendarDataSource
and FSCalendarDelegate
in your ViewController
Or use code
@property (weak , nonatomic) FSCalendar *calendar;
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
fileprivate weak var calendar: FSCalendar!
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
To use FSCalendar in Swift3, see Example-Swift
for details.
Warning
FSCalendar
doesn't update frame by itself, Please implement
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
self.calendarHeightConstraint.constant = CGRectGetHeight(bounds);
[self.view layoutIfNeeded];
}
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
calendar.frame = (CGRect){calendar.frame.origin,bounds.size};
}
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
[calendar mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@(bounds.size.height));
}];
[self.view layoutIfNeeded];
}
func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
calendar.snp.updateConstraints { (make) in
make.height.equalTo(bounds.height)
}
self.view.layoutIfNeeded()
}
Roll with Interface Builder
![fscalendar - ibdesignable](https://cloud.githubusercontent.com/assets/5186464/9301716/2e76a2ca-4503-11e5-8450-1fa7aa93e9fd.gif)
Pre-knowledge
In Swift3
, NSDate
and NSDateFormatter
have been renamed to Date and DateFormatter , see Example-Swift
for details.
How to create NSDate object
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];
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
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];
NSInteger era = [self.gregorian component:NSCalendarUnitEra fromDate:date];
NSInteger year = [self.gregorian component:NSCalendarUnitYear fromDate:date];
NSInteger month = [self.gregorian component:NSCalendarUnitMonth fromDate:date];
NSInteger day = [self.gregorian component:NSCalendarUnitDay fromDate:date];
NSInteger hour = [self.gregorian component:NSCalendarUnitHour fromDate:date];
NSInteger minute = [self.gregorian component:NSCalendarUnitMinute fromDate:date];
...
NSDate *nextMonth = [self.gregorain dateByAddingUnit:NSCalendarUnitMonth value:1 toDate:date options:0];
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];
BOOL sameDay = [self.gregorian isDate:date1 inSameDayAsDate:date2];
[self.gregorian compareDate:date1 toDate:date2 toUnitGranularity:unit];
BOOL inSameUnit = [self.gregorian isDate:date1 equalToDate:date2 toUnitGranularity:unit];
Support this repo
- ★Star this repo
- Support with
- Support with
or
![](http://a4.mzstatic.com/us/r30/Purple49/v4/23/31/14/233114f8-2e8d-7b63-8dc5-85d29893061e/icon175x175.jpeg)
Contact
If your made a beautiful calendar with this library in your app, please take a screen shot and @me in twitter. Your help really means a lot to me!
License
FSCalendar is available under the MIT license. See the LICENSE file for more info.