discover · compare · collections · requirements · contribute · feed · watching · stats · help with your tokens
WenchaoD/FSCalendar · source
Snapshot 0 · 2026-11-04T12:47:23Z · Objective-C · MIT
Content fingerprint
f09e8c965b26ef50536a154e136926dcd59e88a0ba99acf39bc3e1b5aaf1a2bdGitHub description at capture
A fully customizable iOS calendar library, compatible with Objective-C and Swift
README at capture

<br/><br/>
[](https://cocoapods.org/pods/FSCalendar)
[](https://cocoapods.org/pods/FSCalendar)
<br>
[](https://travis-ci.org/WenchaoD/FSCalendar)
[](http://cocoadocs.org/docsets/FSCalendar)
[](http://cocoadocs.org/docsets/FSCalendar)
[](https://github.com/Carthage/Carthage)
[](https://swift.org/package-manager/)
<br>
[](#)
# Table of contents
* [Screenshots](#screenshots)
* [Installation](#installation)
* [Pre-knowledge](#pre-knowledge)
* [Support](#support)
* [Contact](#contact)
## <a id="screenshots"></a>Screenshots
### iPhone

### iPad

### Safe Orientation

### Today Extension
| iOS8/9 | iOS10 |
|--------------|-------------|
|||
### Interactive Scope Gesture
|  |
| ---- |
### DIY support
|  |
| ------------- |
> To customize your own cell, view DIY Example in `Example-Swift` or `Example-Objc`
### Swipe-To-Choose
|Single-Selection<br/>Swipe-To-Choose|Multiple-Selection<br/>Swipe-To-Choose|DIY<br/>Swipe-To-Choose|
|----------|--------|--------|
||||
## Achievement of Users <a id="achievement"></a>
|  |  |  |  |
| ------------- | ------------- | ------------- | ------------- |
#### [***More Achievements***](https://github.com/WenchaoD/FSCalendar/wiki/) are available in [***FSCalendar Gallery***](https://github.com/WenchaoD/FSCalendar/wiki/)
# <a id="installation"></a>Installation
## CocoaPods:
* For iOS8+: 👍
```ruby
use_frameworks!
target '<Your Target Name>' do
pod 'FSCalendar'
end
```
* For iOS7+:
```ruby
target '<Your Target Name>' do
pod 'FSCalendar'
end
```
> [NSCalendarExtension](https://github.com/WenchaoD/NSCalendarExtension) is required to get iOS7 compatibility.
## Carthage:
* For iOS8+
```ruby
github "WenchaoD/FSCalendar"
```
## SPM:
Add dependency:
```swift
.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***. <br>
> Only the methods marked "👍" support IBInspectable / IBDesignable feature. [Have fun with Interface builder](#roll_with_interface_builder)
# Setup
## Use Interface Builder
1、 Drag an UIView object to ViewController Scene
2、 Change the `Custom Class` to `FSCalendar`<br/>
3、 Link `dataSource` and `delegate` to the ViewController <br/>

4、 Finally, implement `FSCalendarDataSource` and `FSCalendarDelegate` in your `ViewController`
## Or use code
```objc
@property (weak , nonatomic) FSCalendar *calendar;
```
```objc
// 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;
```
<br/>
## Or swift
* To use `FSCalendar` in swift, you need to [Create Bridge Header](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html) first.
```swift
fileprivate weak var calendar: FSCalendar!
```
```swift
// 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
```
> To use **FSCalendar** in Swift3, see `Example-Swift` for details.
## <a id='adjusts_frame_dynamicly' /></a>Warning
`FSCalendar` ***doesn't*** update frame by itself, Please implement
* For ***AutoLayout***
```objc
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
self.calendarHeightConstraint.constant = CGRectGetHeight(bounds);
// Do other updates here
[self.view layoutIfNeeded];
}
```
* For ***Manual Layout***
```objc
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
calendar.frame = (CGRect){calendar.frame.origin,bounds.size};
// Do other updates here
}
```
* If you are using ***Masonry***
```objc
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
[calendar mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@(bounds.size.height));
// Do other updates
}];
[self.view layoutIfNeeded];
}
```
* If you are using ***SnapKit***
```swift
func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
calendar.snp.updateConstraints { (make) in
make.height.equalTo(bounds.height)
// Do other updates
}
self.view.layoutIfNeeded()
}
```
### <a id="roll_with_interface_builder"></a> Roll with Interface Builder

# <a id="pre-knowledge"></a>Pre-knowledge
> In `Swift3`, `NSDate` and `NSDateFormatter` have been renamed to ***Date*** and ***DateFormatter*** , see `Example-Swift` for details.
## How to create NSDate object
* By **NSCalendar**.
```objc
self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
```
Then:
```objc
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**
```objc
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateFormat = @"yyyy-MM-dd";
```
Then:
```objc
NSDate *date = [self.formatter dateFromString:@"2016-09-10"];
```
## How to print out NSDate object
* Use **NSDateFormatter**
```objc
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateFormat = @"yyyy/MM/dd";
```
```objc
NSString *string = [self.formatter stringFromDate:date];
NSLog(@"Date is %@", string);
```
## How to manipulate NSDate with NSCalendar
```objc
self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
```
* Get component of NSDate
```objc
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];
...
```
* Get next **month**
```objc
NSDate *nextMonth = [self.gregorain dateByAddingUnit:NSCalendarUnitMonth value:1 toDate:date options:0];
```
* Get next **day**
```objc
NSDate *nextDay = [self.gregorain dateByAddingUnit:NSCalendarUnitDay value:1 toDate:date options:0];
```
* Is date in today/tomorrow/yesterday/weekend
```objc
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
```objc
BOOL sameDay = [self.gregorian isDate:date1 inSameDayAsDate:date2];
// Yes if the date1 and date2 are in same day
[self.gregorian compareDate:date1 toDate:date2 toUnitGranularity:unit];
// compare the era/year/month/day/hour/minute .etc ...
// return NSOrderAscending/NSOrderSame/NSOrderDecending
BOOL inSameUnit = [self.gregorian isDate:date1 equalToDate:date2 toUnitGranularity:unit];
// if the given unit (era/year/month/day/hour/minute .etc) are the same
```
## <a id="support"></a>Support this repo
* [**★Star**](#) this repo
<br/>
* Support with <a href="https://www.paypal.me/WenchaoD" target="_blank"><img src="https://www.paypalobjects.com/webstatic/i/logo/rebrand/ppcom.svg" width="100" height="40" style="margin-bottom:-15px;"></a>
<br/>
* Support with <a href="https://user-images.githubusercontent.com/5186464/45949944-46960480-c030-11e8-9e90-30b015698cf6.png" target="_blank"><img src="http://a1.mzstatic.com/us/r30/Purple49/v4/50/16/b3/5016b341-39c1-b47b-2994-d7e23823baed/icon175x175.png" width="40" height="40" style="margin-bottom:-15px;-webkit-border-radius:10px;border:1px solid rgba(30, 154, 236, 1);"></a> or
<a href="https://cloud.githubusercontent.com/assets/5186464/15096872/b06f3a3a-153c-11e6-89f9-2e9c7b88ef42.png" target="_blank"><img src="http://a4.mzstatic.com/us/r30/Purple49/v4/23/31/14/233114f8-2e8d-7b63-8dc5-85d29893061e/icon175x175.jpeg" height="40" width="40" style="margin-bottom:-15px; -webkit-border-radius: 10px;border:1px solid rgba(43, 177, 0, 1)"></a>
<br/>
## <a id='contact'/></a> Contact
* 微博: [**@WenchaoD**](http://weibo.com/WenchaoD)
* Twitter:[**@WenchaoD**](https://twitter.com/WenchaoD)
* <a id='qq_group'/></a>QQ支持群: <br><br>

> If your made a beautiful calendar with this library in your app, please take a screen shot and [@me](https://twitter.com/WenchaoD) in twitter. Your help really means a lot to me! <br/>
# License
FSCalendar is available under the MIT license. See the LICENSE file for more info.
### [Documentation](http://cocoadocs.org/docsets/FSCalendar/) | [More Usage](https://github.com/WenchaoD/FSCalendar/blob/master/MOREUSAGE.md) | [简书](http://www.jianshu.com/notebooks/4276521/latest)