项目作者: WenchaoD

项目描述 :
完全可定制的iOS日历库,与Objective-C和Swift兼容
高级语言: Objective-C
项目地址: git://github.com/WenchaoD/FSCalendar.git
创建时间: 2015-02-15T08:43:09Z
项目社区:https://github.com/WenchaoD/FSCalendar

开源协议:MIT License

下载


logo



Apps Using
Total Downloads


Travis
Version
Platform
Carthage compatible
SwiftPM


Languages

Table of contents

Screenshots" class="reference-link">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

" class="reference-link">Achievement of Users

1 2 3 4

Installation" class="reference-link">Installation

CocoaPods:

  • For iOS8+: 👍
  1. use_frameworks!
  2. target '<Your Target Name>' do
  3. pod 'FSCalendar'
  4. end
  • For iOS7+:
  1. target '<Your Target Name>' do
  2. pod 'FSCalendar'
  3. end

NSCalendarExtension is required to get iOS7 compatibility.

Carthage:

  • For iOS8+
  1. github "WenchaoD/FSCalendar"

SPM:

Add dependency:

  1. .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

4、 Finally, implement FSCalendarDataSource and FSCalendarDelegate in your ViewController

Or use code

  1. @property (weak , nonatomic) FSCalendar *calendar;
  1. // In loadView(Recommended) or viewDidLoad
  2. FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
  3. calendar.dataSource = self;
  4. calendar.delegate = self;
  5. [self.view addSubview:calendar];
  6. self.calendar = calendar;


Or swift

  1. fileprivate weak var calendar: FSCalendar!
  1. // In loadView or viewDidLoad
  2. let calendar = FSCalendar(frame: CGRect(x: 0, y: 0, width: 320, height: 300))
  3. calendar.dataSource = self
  4. calendar.delegate = self
  5. view.addSubview(calendar)
  6. self.calendar = calendar

To use FSCalendar in Swift3, see Example-Swift for details.

Warning

FSCalendar doesn’t update frame by itself, Please implement

  • For AutoLayout
  1. - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
  2. {
  3. self.calendarHeightConstraint.constant = CGRectGetHeight(bounds);
  4. // Do other updates here
  5. [self.view layoutIfNeeded];
  6. }
  • For Manual Layout
  1. - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
  2. {
  3. calendar.frame = (CGRect){calendar.frame.origin,bounds.size};
  4. // Do other updates here
  5. }
  • If you are using Masonry
  1. - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
  2. {
  3. [calendar mas_updateConstraints:^(MASConstraintMaker *make) {
  4. make.height.equalTo(@(bounds.size.height));
  5. // Do other updates
  6. }];
  7. [self.view layoutIfNeeded];
  8. }
  • If you are using SnapKit
  1. func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
  2. calendar.snp.updateConstraints { (make) in
  3. make.height.equalTo(bounds.height)
  4. // Do other updates
  5. }
  6. self.view.layoutIfNeeded()
  7. }

Roll with Interface Builder" class="reference-link"> Roll with Interface Builder

fscalendar - ibdesignable

Pre-knowledge" class="reference-link">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.
  1. self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];

Then:

  1. NSDate *date = [gregorian dateWithEra:1 year:2016 month:9 day:10 hour:0 minute:0 second:0 nanosecond:0];
  2. // 2016-09-10 00:00:00
  • Or by NSDateFormatter
  1. self.formatter = [[NSDateFormatter alloc] init];
  2. self.formatter.dateFormat = @"yyyy-MM-dd";

Then:

  1. NSDate *date = [self.formatter dateFromString:@"2016-09-10"];

How to print out NSDate object

  • Use NSDateFormatter
  1. self.formatter = [[NSDateFormatter alloc] init];
  2. self.formatter.dateFormat = @"yyyy/MM/dd";
  1. NSString *string = [self.formatter stringFromDate:date];
  2. NSLog(@"Date is %@", string);

How to manipulate NSDate with NSCalendar

  1. self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
  • Get component of NSDate
  1. NSInteger era = [self.gregorian component:NSCalendarUnitEra fromDate:date];
  2. NSInteger year = [self.gregorian component:NSCalendarUnitYear fromDate:date];
  3. NSInteger month = [self.gregorian component:NSCalendarUnitMonth fromDate:date];
  4. NSInteger day = [self.gregorian component:NSCalendarUnitDay fromDate:date];
  5. NSInteger hour = [self.gregorian component:NSCalendarUnitHour fromDate:date];
  6. NSInteger minute = [self.gregorian component:NSCalendarUnitMinute fromDate:date];
  7. ...
  • Get next month
  1. NSDate *nextMonth = [self.gregorain dateByAddingUnit:NSCalendarUnitMonth value:1 toDate:date options:0];
  • Get next day
  1. NSDate *nextDay = [self.gregorain dateByAddingUnit:NSCalendarUnitDay value:1 toDate:date options:0];
  • Is date in today/tomorrow/yesterday/weekend
  1. BOOL isToday = [self.gregorian isDateInToday:date];
  2. BOOL isYesterday = [self.gregorian isDateInYesterday:date];
  3. BOOL isTomorrow = [self.gregorian isDateInTomorrow:date];
  4. BOOL isWeekend = [self.gregorian isDateInWeekend:date];
  • Compare two dates
  1. BOOL sameDay = [self.gregorian isDate:date1 inSameDayAsDate:date2];
  2. // Yes if the date1 and date2 are in same day
  3. [self.gregorian compareDate:date1 toDate:date2 toUnitGranularity:unit];
  4. // compare the era/year/month/day/hour/minute .etc ...
  5. // return NSOrderAscending/NSOrderSame/NSOrderDecending
  6. BOOL inSameUnit = [self.gregorian isDate:date1 equalToDate:date2 toUnitGranularity:unit];
  7. // if the given unit (era/year/month/day/hour/minute .etc) are the same

Support this repo" class="reference-link">Support this repo

  • ★Star this repo

  • Support with

  • Support with or


Contact

fscalendar

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 | 简书