FSCalendar - 一个完全可定制的 iOS 日历库,兼容 Objective-C 和 Swift

Created at: 2015-02-15 16:43:09
Language: Objective-C
License: MIT

商标

应用程序使用 总下载量
崔维斯 版本 平台 与迦太基兼容
语言

目录

截图

苹果手机

fscalendar

平板电脑

fscalendar-ipad

安全定位

fscalendar-scope-orientation-autolayout

今日扩展

iOS8/9 苹果10
今日1 今日2

交互式示波器手势

1

自我设计支持

1

要自定义你自己的单元格,请在 或

Example-Swift
Example-Objc

滑动选择

单选
滑动选择
多选
滑动选择
DIY
滑动选择
1 2 3

用户成就

1 2 3 4

更多成就可在FSCalendar画廊中找到

安装

CocoaPods:

  • 对于 iOS8+: 👍
use_frameworks!
target '<Your Target Name>' do
    pod 'FSCalendar'
end
  • 对于 iOS7+:
target '<Your Target Name>' do
	pod 'FSCalendar'
end

NSCalendarExtension 是获得 iOS7 兼容性所必需的。

迦太基:

  • 适用于 iOS8+
github "WenchaoD/FSCalendar"

SPM:

添加依赖项:

.package(url: "https://github.com/WenchaoD/FSCalendar.git", from: "2.8.3")

手动地:

  • 将文件夹下的所有文件拖到项目中。👍
    FSCalendar

或者,若要对其进行测试运行,只需按 或 并启动 UITest 目标
只有标有“”👍的方法支持IB可检验/IB可设计功能。玩得开心与界面构建器

command+u
Example-Objc
Example-Swift

设置

使用界面生成器

1、 拖动 UIView 对象到视图控制器场景 2、 更改为
3、 链接并到视图控制器

Custom Class
FSCalendar
dataSource
delegate

fscalendar-ib

4、 最后,实施并在你的

FSCalendarDataSource
FSCalendarDelegate
ViewController

或使用代码

@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;

或快速

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

要在 Swift3 中使用 FSCalendar,请参阅了解详细信息。

Example-Swift

警告

FSCalendar
自行更新帧,请实现

  • 对于自动布局
- (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];
}
  • 如果你使用的是 SnapKit
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()
}

使用界面生成器滚动

fscalendar - ibdesignable

知识前期

在 中,并已重命名为“日期日期格式器”,有关详细信息,请参阅。

Swift3
NSDate
NSDateFormatter
Example-Swift

如何创建 NSDate 对象

  • NSCalendar提供
self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];

然后:

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
  • 或通过NSDateFormatter
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateFormat = @"yyyy-MM-dd";

然后:

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

如何打印出 NSDate 对象

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

如何使用 NSCalendar 操作 NSDate

self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
  • 获取 NSDate 的组件
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

支持此存储库


* 支持 *
支持或

联系

如果你在应用程序中使用此库制作了一个漂亮的日历,请拍摄屏幕截图并在twitter中@me。你的帮助对我来说真的意义重大!

许可证

FSCalendar 在 MIT 许可证下可用。有关详细信息,请参阅许可证文件。

文档|更多用法|简书