博客> FSCalendar
FSCalendar
2017-12-13 21:25 评论:0 阅读:1822 西单_夜未央
FSCalendar

周末没有妹子约,只能约电脑--------->>>>>>电脑才是一辈子的"情人"

今天主要介绍一款第三方:FSCalendar 相信很多朋友在开发的过程中遇到日历的开发.

 4FBBB5F4-2843-4B26-B611-C2F4AEB9FCD26156c458-c27d-11e4-97da-52b424b45ec3.gif

个人觉得FSCalendar这款日历插件很漂亮,在网上搜了一下,大家评价都很高,可是貌似没人对此做系统的介绍 (也可能是因为太简单了,但对于一些刚接触的朋友来说系统介绍可以帮他们更加快速,高效开发)

下面是下载地址: https://github.com/f33chobits/FSCalendar

下载完成之后又个范例:  4D24E4F2-6207-4F0A-B2CE-AFC9F32B5F4E.png

下面先从最主要的代理入手: calendar.dataSource = self; calendar.delegate = self; <FSCalendarDataSource>

pragma mark -

//这个能否选定日期

  • (BOOL)calendar:(FSCalendar )calendar shouldSelectDate:(NSDate )date { NSLog(@"should select date %@",[calendar stringFromDate:date format:@"yyyy/MM/dd"]); return YES; }

//选择日期,最主要的方法

  • (void)calendar:(FSCalendar )calendar didSelectDate:(NSDate )date { NSLog(@"did select date %@",[calendar stringFromDate:date format:@"yyyy/MM/dd"]); }

//翻页调用,比如说下个月

  • (void)calendarCurrentPageDidChange:(FSCalendar *)calendar { NSLog(@"did change to page %@",[calendar stringFromDate:calendar.currentPage format:@"MMMM YYYY"]); }

//取消选择调用

  • (void)calendar:(FSCalendar )calendar didDeselectDate:(NSDate )date { NSLog(@"Did deselect date %@",[calendar stringFromDate:date]); }

  • (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated { calendar.frame = (CGRect){calendar.frame.origin,bounds.size}; }

pragma mark -

//下面的两个方法是限制你日期选择的方法

/*

  • (NSDate )minimumDateForCalendar:(FSCalendar )calendar { return [calendar tomorrowOfDate:[NSDate date]]; } */

/*

  • (NSDate )maximumDateForCalendar:(FSCalendar )calendar { return [_calendar dateWithYear:2026 month:12 day:31]; } */

  • (UIImage )calendar:(FSCalendar )calendar imageForDate:(NSDate *)date { return self.images[[calendar stringFromDate:date format:@"yyyy/MM/dd"]]; }

下面是对样式,颜色...自定义 _calendar.appearance.weekdayTextColor = FSCalendarStandardTitleTextColor; _calendar.appearance.headerTitleColor = FSCalendarStandardTitleTextColor; _calendar.appearance.eventColor = FSCalendarStandardEventDotColor; _calendar.appearance.selectionColor = FSCalendarStandardSelectionColor; _calendar.appearance.headerDateFormat = @"MMMM yyyy"; _calendar.appearance.todayColor = FSCalendarStandardTodayColor; _calendar.appearance.cellShape = FSCalendarCellShapeCircle; _calendar.appearance.headerMinimumDissolvedAlpha = 0.2;

            _calendar.appearance.weekdayTextColor = [UIColor redColor];
            _calendar.appearance.headerTitleColor = [UIColor darkGrayColor];
            _calendar.appearance.eventColor = [UIColor greenColor];
            _calendar.appearance.selectionColor = [UIColor blueColor];
            _calendar.appearance.headerDateFormat = @"yyyy-MM";
            _calendar.appearance.todayColor = [UIColor redColor];
            _calendar.appearance.cellShape = FSCalendarCellShapeCircle;
            _calendar.appearance.headerMinimumDissolvedAlpha = 0.0;

            _calendar.appearance.weekdayTextColor = [UIColor redColor];
            _calendar.appearance.headerTitleColor = [UIColor redColor];
            _calendar.appearance.eventColor = [UIColor greenColor];
            _calendar.appearance.selectionColor = [UIColor blueColor];
            _calendar.appearance.headerDateFormat = @"yyyy/MM";
            _calendar.appearance.todayColor = [UIColor orangeColor];
            _calendar.appearance.cellShape = FSCalendarCellShapeRectangle;
            _calendar.appearance.headerMinimumDissolvedAlpha = 1.0;

当然支持横向和纵向 calendar.scrollDirection = FSCalendarScrollDirectionVertical; calendar.scrollDirection = FSCalendarScrollDirectionHorizontal;

还支持农历: _lunarCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese]; _lunarCalendar.locale = [NSLocale localeWithLocaleIdentifier:@"zh-CN"]; _lunarChars = @[@"初一",@"初二",@"初三",@"初四",@"初五",@"初六",@"初七",@"初八",@"初九",@"初十",@"十一",@"十二",@"十三",@"十四",@"十五",@"十六",@"十七",@"十八",@"十九",@"二十",@"二一",@"二二",@"二三",@"二四",@"二五",@"二六",@"二七",@"二八",@"二九",@"三十"];

  • (NSString )calendar:(FSCalendar )calendar subtitleForDate:(NSDate *)date { if (!_lunar) { return nil; } NSInteger day = [_lunarCalendar components:NSCalendarUnitDay fromDate:date].day; return _lunarChars[day-1]; }

还支持多选 calendar.allowsMultipleSelection = YES;

注意一个细节:在加载View,导航栏会遮挡日历 FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.navigationController.navigationBar.frame), view.bounds.size.width, height)];

就介绍这个多吧!应该够用,想继续研究的请自行下载FSCalendar

收藏
1
sina weixin mail 回到顶部