FSCalendar README

The project's README from github.com/WenchaoD/FSCalendar. As one markdown file: README.md.

logo

Apps Using Total Downloads
Travis Version Platform Carthage compatible SwiftPM
Languages

Table of contents

Screenshots

iPhone

fscalendar

iPad

fscalendar-ipad

Safe Orientation

fscalendar-scope-orientation-autolayout

Today Extension

iOS8/9 iOS10
today1 today2

Interactive Scope Gesture

1

DIY support

1

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 2 3

Achievement of Users

1 2 3 4

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:

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

4、 Finally, implement FSCalendarDataSource and FSCalendarDelegate in your ViewController

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

fileprivate 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

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);
    // Do other updates here
    [self.view layoutIfNeeded];
}
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
    calendar.frame = (CGRect){calendar.frame.origin,bounds.size};
    // Do other updates here
}
- (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];
}
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()
}

Roll with Interface Builder

fscalendar - ibdesignable

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];
// 2016-09-10 00:00:00
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];
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];
// 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

Support this repo


* Support with  
* Support with or

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.

Documentation | More Usage | 简书

FSCalendar (WenchaoD/FSCalendar)

Searching Database…

这是什么?FSCalendar 是一个 iOS 平台上完全可自定义的日历界面库,Objective-C 和 Swift 项目都能使用。
它是一个现成的日历应用,还是添加到我自己的 Xcode 项目里的代码?它是一个库,不是应用:一个 UIView 的子类,你可以把它放进自己的页面,通过 dataSource 和 delegate 来驱动它。
我该怎么把它加到我的应用里?可以通过 CocoaPods(iOS 8 及以上版本推荐使用)、Carthage 或 SPM 安装,也可以直接把 FSCalendar 的源码文件拖进项目;然后把某个 UIView 的自定义类设置为 FSCalendar,并实现它对应的协议。
它支持哪些 iOS 版本?CocoaPods、Carthage 和 SPM 方式安装时支持 iOS 8 及以上;如果启用 NSCalendarExtension,通过 CocoaPods 仍然可以用在 iOS 7 上。
日历会自己排好布局吗,还是有什么坑?确实有个坑:它不会自己更新 frame,布局需要你自己实现——可以用 AutoLayout 约束、手动布局,如果用了 Masonry 或 SnapKit 也可以借助它们的辅助方法。
我能在自己的应用里使用它吗,包括商业应用?可以——它采用 MIT 许可证,商用完全没问题;作者只是希望如果你用做出了不错的作品,给项目点个 star,并在 Twitter 上发张截图提一下。
我的应用是用 Swift 写的,使用它有什么要注意的吗?有:需要先创建一个桥接头文件。仓库里附带一个 Example-Swift 示例项目,展示了完整的配置过程,包括 Swift 3 的改名,比如 Date 和 DateFormatter。
它到底能自定义到什么程度?完全可自定义:你可以提供自己的日期单元格(Example-Swift 和 Example-Objc 里都附带了一个 DIY 示例),演示项目还涵盖了单选、多选以及 DIY 的滑动选择。
除了普通的 iPhone 屏幕,它还能出现在哪些地方?README 里展示了它在 iPhone 和 iPad 上的效果,支持屏幕方向安全切换,甚至可以嵌入 iOS 8/9/10 的 Today 小组件扩展中。
集成之前我能先试试吗?可以——打开 Example-Objc 或 Example-Swift 项目,按下 command+u 即可运行 UITest 目标。
Creator
WenchaoD
Size
2.5 MB
Stars
10.6K
Age
11y
Commits · 90 Days