iOS8/9 | 苹果10 |
---|---|
![]() |
![]() |
![]() |
---|
![]() |
---|
要自定义你自己的单元格,请在 或
Example-SwiftExample-Objc
单选 滑动选择 |
多选 滑动选择 |
DIY 滑动选择 |
---|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
---|
use_frameworks!
target '<Your Target Name>' do
pod 'FSCalendar'
end
target '<Your Target Name>' do
pod 'FSCalendar'
end
NSCalendarExtension 是获得 iOS7 兼容性所必需的。
github "WenchaoD/FSCalendar"
添加依赖项:
.package(url: "https://github.com/WenchaoD/FSCalendar.git", from: "2.8.3")
FSCalendar
或者,若要对其进行测试运行,只需按 或 并启动 UITest 目标。
只有标有“”👍 的方法支持IB可检验/IB可设计功能。玩得开心与界面构建器command+uExample-ObjcExample-Swift
1、 拖动 UIView 对象到视图控制器场景 2、 更改为
3、 链接并到视图控制器
Custom Class
FSCalendar
dataSource
delegate
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;
FSCalendar
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];
}
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()
}
在 中,并已重命名为“日期和日期格式器”,有关详细信息,请参阅。
Swift3NSDateNSDateFormatterExample-Swift
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"];
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateFormat = @"yyyy/MM/dd";
NSString *string = [self.formatter stringFromDate:date];
NSLog(@"Date is %@", string);
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中@me。你的帮助对我来说真的意义重大!
FSCalendar 在 MIT 许可证下可用。有关详细信息,请参阅许可证文件。