logo

Apps Using Total Downloads
Travis Version Platform Carthage compatible SwiftPM
Languages

目录

截图

iPhone

fscalendar

iPad

fscalendar-ipad

安全方向

fscalendar-scope-orientation-autolayout

今日扩展

iOS8/9 iOS10
today1 today2

交互范围手势

1

DIY 支持

1

要自定义你的单元格,请查看 Example-SwiftExample-Objc 中的 DIY 示例

滑动选择

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

用户成就

1 2 3 4

更多成就 可在 FSCalendar Gallery 中查看

安装

CocoaPods

use_frameworks!
target '<Your Target Name>' do
    pod 'FSCalendar'
end
target '<Your Target Name>' do
	pod 'FSCalendar'
end

需要 NSCalendarExtension 以获得 iOS7 的兼容性。

Carthage

github "WenchaoD/FSCalendar"

SPM

添加依赖

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

手动

或者,为了试运行,只需在 Example-ObjcExample-Swift 中按 command+u 并启动 *UITest Target*。
只有标记为 "👍" 的方法支持 IBInspectable / IBDesignable 功能。 尽情使用 Interface Builder 吧

设置

使用 Interface Builder

1、将一个 UIView 对象拖到 ViewController Scene 2、将 Custom Class 更改为 FSCalendar
3、将 dataSourcedelegate 连接到 ViewController

fscalendar-ib

4、最后,在你的 ViewController 中实现 FSCalendarDataSourceFSCalendarDelegate

或者使用代码

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

或者 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

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

警告

FSCalendar *不会* 自行更新 frame,请实现

- (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()
}

尽情使用 Interface Builder 吧

fscalendar - ibdesignable

预备知识

Swift3 中,NSDateNSDateFormatter 已重命名为 *Date* 和 *DateFormatter*,请参阅 Example-Swift 以了解详细信息。

如何创建 NSDate 对象

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

然后

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

如何打印 NSDate 对象

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];
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 上 @我。您的帮助对我来说意义重大!

许可证

FSCalendar 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。

文档 | 更多用法 | 简书