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 custom class равным FSCalendar и реализуйте его протоколы.
На каких версиях iOS он работает?iOS 8 и выше при установке через CocoaPods, Carthage и SPM; iOS 7 тоже доступна через CocoaPods, если включить NSCalendarExtension.
Календарь сам настроит свою разметку или есть подвох?Подвох есть: он никогда не обновляет свой frame, так что вёрстку вы делаете сами — через констрейнты AutoLayout, вручную или с помощью библиотек вроде Masonry или SnapKit.
Могу ли я использовать его в своём приложении, в том числе платном?Да — лицензия MIT, так что коммерческое использование разрешено; автор лишь просит поставить звёздочку и поделиться скриншотом в Twitter, если у вас получится что-то классное.
Я пишу приложение на Swift — есть ли особенности при использовании?Да: сначала нужно создать bridging header. В репозитории есть проект Example-Swift с полной настройкой, включая переименования из Swift 3 вроде Date и DateFormatter.
Насколько сильно его можно настраивать?Полностью: можно подставить собственные ячейки с датами (пример DIY есть и в Example-Swift, и в Example-Objc), а в демо показаны одиночный выбор, множественный выбор и DIY-выбор свайпом.
Где ещё он может отображаться, кроме обычного экрана iPhone?В README он показан на iPhone и iPad, при смене ориентации и даже внутри расширения Today widget в iOS 8/9/10.
Можно ли попробовать его до интеграции?Да — откройте проект Example-Objc или Example-Swift и нажмите command+u, чтобы запустить UITest-таргет.
Creator
WenchaoD
Size
2.5 MB
Stars
10.6K
Age
11y
Commits · 90 Days