Create branch 0.9.0
1. Change month-change delegate routine:
before: when the scrollOffset reach half of the size of screen
now: when releasing your finger
2. Use calendar.appearance to change color、font and other stuff of
FSCalendar
This commit is contained in:
parent
4c2bdc057d
commit
2ed1abdfdc
|
|
@ -33,13 +33,12 @@
|
|||
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
|
||||
|
||||
_currentCalendar = [NSCalendar currentCalendar];
|
||||
_flow = _calendar.flow;
|
||||
// _firstWeekday = _calendar.firstWeekday;
|
||||
// _calendar.firstWeekday = 2;
|
||||
// _calendar.firstWeekday = 2; // Monday
|
||||
// _calendar.flow = FSCalendarFlowVertical;
|
||||
// _calendar.selectedDate = [NSDate fs_dateWithYear:2015 month:2 day:1];
|
||||
|
||||
// _calendar.headerDateFormat = [NSDateFormatter dateFormatFromTemplate:@"MMMM yyyy" options:0 locale:[NSLocale localeWithLocaleIdentifier:@"it_IT"]];
|
||||
_flow = _calendar.flow;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -117,40 +116,38 @@
|
|||
if (_theme != theme) {
|
||||
_theme = theme;
|
||||
switch (theme) {
|
||||
case 0:
|
||||
{
|
||||
[_calendar setWeekdayTextColor:kBlueText];
|
||||
[_calendar setHeaderTitleColor:kBlueText];
|
||||
[_calendar setEventColor:[kBlueText colorWithAlphaComponent:0.75]];
|
||||
[_calendar setSelectionColor:kBlue];
|
||||
[_calendar setHeaderDateFormat:@"MMMM yyyy"];
|
||||
[_calendar setMinDissolvedAlpha:0.2];
|
||||
[_calendar setTodayColor:kPink];
|
||||
[_calendar setCellStyle:FSCalendarCellStyleCircle];
|
||||
case 0: {
|
||||
_calendar.appearance.weekdayTextColor = kBlueText;
|
||||
_calendar.appearance.headerTitleColor = kBlueText;
|
||||
_calendar.appearance.eventColor = [kBlueText colorWithAlphaComponent:0.75];
|
||||
_calendar.appearance.selectionColor = kBlue;
|
||||
_calendar.appearance.headerDateFormat = @"MMMM yyyy";
|
||||
_calendar.appearance.todayColor = kPink;
|
||||
_calendar.appearance.cellStyle = FSCalendarCellStyleCircle;
|
||||
_calendar.appearance.headerMinimumDissolvedAlpha = 0.2;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
[_calendar setWeekdayTextColor:[UIColor redColor]];
|
||||
[_calendar setHeaderTitleColor:[UIColor darkGrayColor]];
|
||||
[_calendar setEventColor:[UIColor greenColor]];
|
||||
[_calendar setSelectionColor:[UIColor blueColor]];
|
||||
[_calendar setHeaderDateFormat:@"yyyy-MM"];
|
||||
[_calendar setMinDissolvedAlpha:1.0];
|
||||
[_calendar setTodayColor:[UIColor redColor]];
|
||||
[_calendar setCellStyle:FSCalendarCellStyleCircle];
|
||||
case 1: {
|
||||
_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.cellStyle = FSCalendarCellStyleCircle;
|
||||
_calendar.appearance.headerMinimumDissolvedAlpha = 0.0;
|
||||
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
[_calendar setWeekdayTextColor:[UIColor redColor]];
|
||||
[_calendar setHeaderTitleColor:[UIColor redColor]];
|
||||
[_calendar setEventColor:[UIColor greenColor]];
|
||||
[_calendar setSelectionColor:[UIColor blueColor]];
|
||||
[_calendar setHeaderDateFormat:@"yyyy/MM"];
|
||||
[_calendar setMinDissolvedAlpha:1.0];
|
||||
[_calendar setCellStyle:FSCalendarCellStyleRectangle];
|
||||
[_calendar setTodayColor:[UIColor orangeColor]];
|
||||
case 2: {
|
||||
_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.cellStyle = FSCalendarCellStyleRectangle;
|
||||
_calendar.appearance.headerMinimumDissolvedAlpha = 1.0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
PODS:
|
||||
- FSCalendar (0.8.1)
|
||||
- FSCalendar (0.9.0)
|
||||
- SSLunarDate (0.0.1)
|
||||
|
||||
DEPENDENCIES:
|
||||
|
|
@ -11,7 +11,7 @@ EXTERNAL SOURCES:
|
|||
:path: ../
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
FSCalendar: b8c459cdf9ef97822b4b13262e8132438e23d794
|
||||
FSCalendar: 87f821dcaa0aa5f0581e2f251741a8ef3c4c0130
|
||||
SSLunarDate: d5d7d581f7e7e157c8d704a5f053b4ebcf760bba
|
||||
|
||||
COCOAPODS: 0.37.2
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
../../../../../Pod/Classes/FSCalendarAppearance.h
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../../../../Pod/Classes/FSCalendarDynamicHeader.h
|
||||
|
|
@ -1 +0,0 @@
|
|||
../../../../../Pod/Classes/NSCalendar+FSExtension.h
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../../../../Pod/Classes/FSCalendarAppearance.h
|
||||
|
|
@ -0,0 +1 @@
|
|||
../../../../../Pod/Classes/FSCalendarDynamicHeader.h
|
||||
|
|
@ -1 +0,0 @@
|
|||
../../../../../Pod/Classes/NSCalendar+FSExtension.h
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "FSCalendar",
|
||||
"version": "0.8.1",
|
||||
"version": "0.9.0",
|
||||
"summary": "A powerful calendar which supports Appearance, Infinite Scrolling and Subtitle",
|
||||
"homepage": "https://github.com/f33chobits/FSCalendar",
|
||||
"screenshots": [
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
},
|
||||
"source": {
|
||||
"git": "https://github.com/f33chobits/FSCalendar.git",
|
||||
"tag": "0.8.1"
|
||||
"tag": "0.9.0"
|
||||
},
|
||||
"platforms": {
|
||||
"ios": "7.0"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
PODS:
|
||||
- FSCalendar (0.8.1)
|
||||
- FSCalendar (0.9.0)
|
||||
- SSLunarDate (0.0.1)
|
||||
|
||||
DEPENDENCIES:
|
||||
|
|
@ -11,7 +11,7 @@ EXTERNAL SOURCES:
|
|||
:path: ../
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
FSCalendar: b8c459cdf9ef97822b4b13262e8132438e23d794
|
||||
FSCalendar: 87f821dcaa0aa5f0581e2f251741a8ef3c4c0130
|
||||
SSLunarDate: d5d7d581f7e7e157c8d704a5f053b4ebcf760bba
|
||||
|
||||
COCOAPODS: 0.37.2
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -14,7 +14,7 @@
|
|||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "6444A509D5C8C2AA593EDADE"
|
||||
BlueprintIdentifier = "75EC11029C55732281867FE2"
|
||||
BuildableName = "libPods-FSCalendar-FSCalendar.a"
|
||||
BlueprintName = "Pods-FSCalendar-FSCalendar"
|
||||
ReferencedContainer = "container:Pods.xcodeproj">
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "6541D62B92A348B2001F5684"
|
||||
BlueprintIdentifier = "57C6052CB36EB543F41E2C9F"
|
||||
BuildableName = "libPods-Tests-FSCalendar.a"
|
||||
BlueprintName = "Pods-Tests-FSCalendar"
|
||||
ReferencedContainer = "container:Pods.xcodeproj">
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
// FSCalendar
|
||||
#define COCOAPODS_POD_AVAILABLE_FSCalendar
|
||||
#define COCOAPODS_VERSION_MAJOR_FSCalendar 0
|
||||
#define COCOAPODS_VERSION_MINOR_FSCalendar 8
|
||||
#define COCOAPODS_VERSION_PATCH_FSCalendar 1
|
||||
#define COCOAPODS_VERSION_MINOR_FSCalendar 9
|
||||
#define COCOAPODS_VERSION_PATCH_FSCalendar 0
|
||||
|
||||
// SSLunarDate
|
||||
#define COCOAPODS_POD_AVAILABLE_SSLunarDate
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@
|
|||
// FSCalendar
|
||||
#define COCOAPODS_POD_AVAILABLE_FSCalendar
|
||||
#define COCOAPODS_VERSION_MAJOR_FSCalendar 0
|
||||
#define COCOAPODS_VERSION_MINOR_FSCalendar 8
|
||||
#define COCOAPODS_VERSION_PATCH_FSCalendar 1
|
||||
#define COCOAPODS_VERSION_MINOR_FSCalendar 9
|
||||
#define COCOAPODS_VERSION_PATCH_FSCalendar 0
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
Pod::Spec.new do |s|
|
||||
|
||||
s.name = "FSCalendar"
|
||||
s.version = "0.8.1"
|
||||
s.version = "0.9.0"
|
||||
s.summary = "A powerful calendar which supports Appearance, Infinite Scrolling and Subtitle"
|
||||
|
||||
s.homepage = "https://github.com/f33chobits/FSCalendar"
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "FSCalendarAppearance.h"
|
||||
|
||||
@class FSCalendar;
|
||||
|
||||
|
|
@ -19,10 +20,6 @@ typedef NS_ENUM(NSInteger, FSCalendarFlow) {
|
|||
FSCalendarFlowHorizontal
|
||||
};
|
||||
|
||||
typedef NS_OPTIONS(NSInteger, FSCalendarCellStyle) {
|
||||
FSCalendarCellStyleCircle = 0,
|
||||
FSCalendarCellStyleRectangle = 1
|
||||
};
|
||||
|
||||
typedef NS_OPTIONS(NSInteger, FSCalendarCellState) {
|
||||
FSCalendarCellStateNormal = 0,
|
||||
|
|
@ -45,7 +42,6 @@ typedef NS_OPTIONS(NSInteger, FSCalendarCellState) {
|
|||
@protocol FSCalendarDataSource <NSObject>
|
||||
|
||||
@optional
|
||||
|
||||
- (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date;
|
||||
- (BOOL)calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date;
|
||||
- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar;
|
||||
|
|
@ -53,10 +49,11 @@ typedef NS_OPTIONS(NSInteger, FSCalendarCellState) {
|
|||
|
||||
@end
|
||||
|
||||
@interface FSCalendar : UIView<UIAppearance>
|
||||
|
||||
@property (weak, nonatomic) IBOutlet id<FSCalendarDelegate> delegate;
|
||||
@property (weak, nonatomic) IBOutlet id<FSCalendarDataSource> dataSource;
|
||||
@interface FSCalendar : UIView
|
||||
|
||||
@property (weak, nonatomic) IBOutlet id<FSCalendarDelegate> delegate;
|
||||
@property (weak, nonatomic) IBOutlet id<FSCalendarDataSource> dataSource;
|
||||
|
||||
@property (strong, nonatomic) NSDate *currentDate;
|
||||
@property (strong, nonatomic) NSDate *selectedDate;
|
||||
|
|
@ -64,35 +61,11 @@ typedef NS_OPTIONS(NSInteger, FSCalendarCellState) {
|
|||
|
||||
@property (assign, nonatomic) FSCalendarFlow flow;
|
||||
@property (assign, nonatomic) IBInspectable NSUInteger firstWeekday;
|
||||
@property (assign, nonatomic) IBInspectable BOOL autoAdjustTitleSize;
|
||||
@property (assign, nonatomic) IBInspectable CGFloat headerHeight;
|
||||
@property (assign, nonatomic) IBInspectable CGFloat minDissolvedAlpha;
|
||||
@property (assign, nonatomic) FSCalendarCellStyle cellStyle;
|
||||
|
||||
@property (strong, nonatomic) UIFont *titleFont;
|
||||
@property (strong, nonatomic) UIFont *subtitleFont;
|
||||
@property (strong, nonatomic) UIFont *weekdayFont;
|
||||
@property (strong, nonatomic) UIColor *eventColor;
|
||||
@property (strong, nonatomic) UIColor *weekdayTextColor;
|
||||
|
||||
@property (strong, nonatomic) UIColor *headerTitleColor;
|
||||
@property (strong, nonatomic) NSString *headerDateFormat;
|
||||
@property (strong, nonatomic) UIFont *headerTitleFont;
|
||||
|
||||
@property (strong, nonatomic) UIColor *titleDefaultColor;
|
||||
@property (strong, nonatomic) UIColor *titleSelectionColor;
|
||||
@property (strong, nonatomic) UIColor *titleTodayColor;
|
||||
@property (strong, nonatomic) UIColor *titlePlaceholderColor;
|
||||
@property (strong, nonatomic) UIColor *titleWeekendColor;
|
||||
|
||||
@property (strong, nonatomic) UIColor *subtitleDefaultColor;
|
||||
@property (strong, nonatomic) UIColor *subtitleSelectionColor;
|
||||
@property (strong, nonatomic) UIColor *subtitleTodayColor;
|
||||
@property (strong, nonatomic) UIColor *subtitlePlaceholderColor;
|
||||
@property (strong, nonatomic) UIColor *subtitleWeekendColor;
|
||||
|
||||
@property (strong, nonatomic) UIColor *selectionColor;
|
||||
@property (strong, nonatomic) UIColor *todayColor;
|
||||
@property (readonly, nonatomic) FSCalendarAppearance *appearance;
|
||||
@property (readonly, nonatomic) NSDate *minimumDate;
|
||||
@property (readonly, nonatomic) NSDate *maximumDate;
|
||||
|
||||
- (void)reloadData;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,14 +10,12 @@
|
|||
#import "FSCalendarHeader.h"
|
||||
#import "UIView+FSExtension.h"
|
||||
#import "NSDate+FSExtension.h"
|
||||
#import "NSCalendar+FSExtension.h"
|
||||
#import "FSCalendarCell.h"
|
||||
|
||||
#import "FSCalendarDynamicHeader.h"
|
||||
|
||||
#define kDefaultHeaderHeight 40
|
||||
#define kWeekHeight roundf(self.fs_height/12)
|
||||
#define kBlueText [UIColor colorWithRed:14/255.0 green:69/255.0 blue:221/255.0 alpha:1.0]
|
||||
#define kPink [UIColor colorWithRed:198/255.0 green:51/255.0 blue:42/255.0 alpha:1.0]
|
||||
#define kBlue [UIColor colorWithRed:31/255.0 green:119/255.0 blue:219/255.0 alpha:1.0]
|
||||
|
||||
@interface FSCalendar (DataSourceAndDelegate)
|
||||
|
||||
|
|
@ -31,26 +29,21 @@
|
|||
@end
|
||||
|
||||
@interface FSCalendar ()<UICollectionViewDataSource, UICollectionViewDelegate>
|
||||
|
||||
{
|
||||
FSCalendarAppearance *_appearance;
|
||||
NSDate *_minimumDate;
|
||||
NSDate *_maximumDate;
|
||||
}
|
||||
@property (strong, nonatomic) NSMutableArray *weekdays;
|
||||
|
||||
@property (strong, nonatomic) NSMutableDictionary *backgroundColors;
|
||||
@property (strong, nonatomic) NSMutableDictionary *titleColors;
|
||||
@property (strong, nonatomic) NSMutableDictionary *subtitleColors;
|
||||
|
||||
@property (weak , nonatomic) CALayer *topBorderLayer;
|
||||
@property (weak , nonatomic) CALayer *bottomBorderLayer;
|
||||
@property (weak , nonatomic) UICollectionView *collectionView;
|
||||
@property (weak , nonatomic) UICollectionViewFlowLayout *collectionViewFlowLayout;
|
||||
@property (weak , nonatomic) FSCalendarHeader *header;
|
||||
|
||||
@property (strong, nonatomic) NSDate *minimumDate;
|
||||
@property (strong, nonatomic) NSDate *maximumDate;
|
||||
@property (strong, nonatomic) NSCalendar *calendar;
|
||||
@property (assign, nonatomic) BOOL supressEvent;
|
||||
@property (assign, nonatomic) BOOL needsLayout;
|
||||
|
||||
- (void)adjustTitleIfNecessary;
|
||||
|
||||
- (void)orientationDidChange:(NSNotification *)notification;
|
||||
|
||||
|
|
@ -92,11 +85,9 @@
|
|||
|
||||
- (void)initialize
|
||||
{
|
||||
_titleFont = [UIFont systemFontOfSize:15];
|
||||
_subtitleFont = [UIFont systemFontOfSize:10];
|
||||
_weekdayFont = [UIFont systemFontOfSize:15];
|
||||
_headerTitleFont = [UIFont systemFontOfSize:15];
|
||||
_headerTitleColor = kBlueText;
|
||||
_appearance = [[FSCalendarAppearance alloc] init];
|
||||
_appearance.calendar = self;
|
||||
|
||||
_headerHeight = -1;
|
||||
_calendar = [NSCalendar currentCalendar];
|
||||
|
||||
|
|
@ -106,8 +97,8 @@
|
|||
UILabel *weekdayLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
weekdayLabel.text = weekSymbols[i];
|
||||
weekdayLabel.textAlignment = NSTextAlignmentCenter;
|
||||
weekdayLabel.font = _weekdayFont;
|
||||
weekdayLabel.textColor = kBlueText;
|
||||
weekdayLabel.font = _appearance.weekdayFont;
|
||||
weekdayLabel.textColor = _appearance.weekdayTextColor;
|
||||
[_weekdays addObject:weekdayLabel];
|
||||
[self addSubview:weekdayLabel];
|
||||
}
|
||||
|
|
@ -116,8 +107,7 @@
|
|||
_firstWeekday = [_calendar firstWeekday];
|
||||
|
||||
FSCalendarHeader *header = [[FSCalendarHeader alloc] initWithFrame:CGRectZero];
|
||||
header.titleFont = _headerTitleFont;
|
||||
header.titleColor = _headerTitleColor;
|
||||
header.appearance = _appearance;
|
||||
[self addSubview:header];
|
||||
self.header = header;
|
||||
|
||||
|
|
@ -125,6 +115,7 @@
|
|||
collectionViewFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
||||
collectionViewFlowLayout.minimumInteritemSpacing = 0;
|
||||
collectionViewFlowLayout.minimumLineSpacing = 0;
|
||||
collectionViewFlowLayout.itemSize = CGSizeMake(1, 1);
|
||||
self.collectionViewFlowLayout = collectionViewFlowLayout;
|
||||
|
||||
|
||||
|
|
@ -146,31 +137,6 @@
|
|||
_currentDate = [NSDate date];
|
||||
_currentMonth = [_currentDate copy];
|
||||
|
||||
_backgroundColors = [NSMutableDictionary dictionaryWithCapacity:4];
|
||||
_backgroundColors[@(FSCalendarCellStateNormal)] = [UIColor clearColor];
|
||||
_backgroundColors[@(FSCalendarCellStateSelected)] = kBlue;
|
||||
_backgroundColors[@(FSCalendarCellStateDisabled)] = [UIColor clearColor];
|
||||
_backgroundColors[@(FSCalendarCellStatePlaceholder)] = [UIColor clearColor];
|
||||
_backgroundColors[@(FSCalendarCellStateToday)] = kPink;
|
||||
|
||||
_titleColors = [NSMutableDictionary dictionaryWithCapacity:4];
|
||||
_titleColors[@(FSCalendarCellStateNormal)] = [UIColor darkTextColor];
|
||||
_titleColors[@(FSCalendarCellStateSelected)] = [UIColor whiteColor];
|
||||
_titleColors[@(FSCalendarCellStateDisabled)] = [UIColor grayColor];
|
||||
_titleColors[@(FSCalendarCellStatePlaceholder)] = [UIColor lightGrayColor];
|
||||
_titleColors[@(FSCalendarCellStateToday)] = [UIColor whiteColor];
|
||||
|
||||
_subtitleColors = [NSMutableDictionary dictionaryWithCapacity:4];
|
||||
_subtitleColors[@(FSCalendarCellStateNormal)] = [UIColor darkGrayColor];
|
||||
_subtitleColors[@(FSCalendarCellStateSelected)] = [UIColor whiteColor];
|
||||
_subtitleColors[@(FSCalendarCellStateDisabled)] = [UIColor lightGrayColor];
|
||||
_subtitleColors[@(FSCalendarCellStatePlaceholder)] = [UIColor lightGrayColor];
|
||||
_subtitleColors[@(FSCalendarCellStateToday)] = [UIColor whiteColor];
|
||||
|
||||
_eventColor = [kBlue colorWithAlphaComponent:0.75];
|
||||
_cellStyle = FSCalendarCellStyleCircle;
|
||||
_autoAdjustTitleSize = YES;
|
||||
|
||||
CALayer *topBorderLayer = [CALayer layer];
|
||||
topBorderLayer.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.2].CGColor;
|
||||
[self.layer addSublayer:topBorderLayer];
|
||||
|
|
@ -228,7 +194,7 @@
|
|||
width,
|
||||
height);
|
||||
}];
|
||||
[self adjustTitleIfNecessary];
|
||||
[_appearance adjustTitleIfNecessary];
|
||||
NSDate *maximumDate = self.maximumDate;
|
||||
NSDate *minimumDate = self.minimumDate;
|
||||
if ([maximumDate fs_daysFrom:minimumDate] <= 0) {
|
||||
|
|
@ -280,15 +246,9 @@
|
|||
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
FSCalendarCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
|
||||
cell.titleColors = self.titleColors;
|
||||
cell.subtitleColors = self.subtitleColors;
|
||||
cell.backgroundColors = self.backgroundColors;
|
||||
cell.eventColor = self.eventColor;
|
||||
cell.cellStyle = self.cellStyle;
|
||||
cell.appearance = self.appearance;
|
||||
cell.month = [_minimumDate fs_dateByAddingMonths:indexPath.section];
|
||||
cell.currentDate = self.currentDate;
|
||||
cell.titleLabel.font = _titleFont;
|
||||
cell.subtitleLabel.font = _subtitleFont;
|
||||
cell.date = [self dateForIndexPath:indexPath];
|
||||
cell.subtitle = [self subtitleForDate:cell.date];
|
||||
cell.hasEvent = [self hasEventForDate:cell.date];
|
||||
|
|
@ -328,24 +288,38 @@
|
|||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
||||
{
|
||||
if (!_minimumDate) {
|
||||
if (!_minimumDate || _supressEvent) {
|
||||
return;
|
||||
}
|
||||
CGFloat scrollOffset = MAX(scrollView.contentOffset.x/scrollView.fs_width,
|
||||
scrollView.contentOffset.y/scrollView.fs_height);
|
||||
NSDate *currentMonth = [_minimumDate fs_dateByAddingMonths:round(scrollOffset)];
|
||||
|
||||
BOOL monthChanged = NO;
|
||||
if (![_currentMonth fs_isEqualToDateForMonth:currentMonth]) {
|
||||
_currentMonth = [currentMonth copy];
|
||||
monthChanged = YES;
|
||||
}
|
||||
if (monthChanged && !_supressEvent) {
|
||||
[self currentMonthDidChange];
|
||||
}
|
||||
_header.scrollOffset = scrollOffset;
|
||||
}
|
||||
|
||||
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
|
||||
{
|
||||
CGFloat pannedOffset = 0, targetOffset = 0, currentOffset = 0, contentSize = 0;
|
||||
if (_flow == FSCalendarFlowHorizontal) {
|
||||
pannedOffset = [scrollView.panGestureRecognizer translationInView:scrollView].x;
|
||||
targetOffset = (*targetContentOffset).x;
|
||||
currentOffset = scrollView.contentOffset.x;
|
||||
contentSize = scrollView.fs_width;
|
||||
} else if (_flow == FSCalendarFlowVertical) {
|
||||
pannedOffset = [scrollView.panGestureRecognizer translationInView:scrollView].y;
|
||||
targetOffset = (*targetContentOffset).y;
|
||||
currentOffset = scrollView.contentOffset.y;
|
||||
contentSize = scrollView.fs_height;
|
||||
}
|
||||
BOOL shouldTriggerMonthChange = ((pannedOffset < 0 && targetOffset > currentOffset) ||
|
||||
(pannedOffset > 0 && targetOffset < currentOffset)) && _minimumDate;
|
||||
if (shouldTriggerMonthChange) {
|
||||
[self willChangeValueForKey:@"currentMonth"];
|
||||
_currentMonth = [_minimumDate fs_dateByAddingMonths:targetOffset/contentSize];
|
||||
[self currentMonthDidChange];
|
||||
[self didChangeValueForKey:@"currentMonth"];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Notification
|
||||
|
||||
- (void)orientationDidChange:(NSNotification *)notification
|
||||
|
|
@ -355,6 +329,18 @@
|
|||
|
||||
#pragma mark - Properties
|
||||
|
||||
- (void)setAppearance:(FSCalendarAppearance *)appearance
|
||||
{
|
||||
if (_appearance != appearance) {
|
||||
_appearance = appearance;
|
||||
}
|
||||
}
|
||||
|
||||
- (FSCalendarAppearance *)appearance
|
||||
{
|
||||
return _appearance;
|
||||
}
|
||||
|
||||
- (void)setFlow:(FSCalendarFlow)flow
|
||||
{
|
||||
if (self.flow != flow) {
|
||||
|
|
@ -406,6 +392,10 @@
|
|||
[self collectionView:_collectionView didSelectItemAtIndexPath:selectedIndexPath];
|
||||
}
|
||||
if (!_collectionView.tracking && !_collectionView.decelerating) {
|
||||
[self willChangeValueForKey:@"currentMonth"];
|
||||
_currentMonth = [selectedDate copy];
|
||||
[self currentMonthDidChange];
|
||||
[self didChangeValueForKey:@"currentMonth"];
|
||||
[self scrollToDate:selectedDate animate:animate];
|
||||
}
|
||||
}
|
||||
|
|
@ -438,48 +428,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void)setWeekdayFont:(UIFont *)weekdayFont
|
||||
{
|
||||
if (![_weekdayFont isEqual:weekdayFont]) {
|
||||
_weekdayFont = weekdayFont;
|
||||
[_weekdays setValue:weekdayFont forKeyPath:@"font"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setWeekdayTextColor:(UIColor *)weekdayTextColor
|
||||
{
|
||||
if (![_weekdayTextColor isEqual:weekdayTextColor]) {
|
||||
_weekdayTextColor = weekdayTextColor;
|
||||
[_weekdays setValue:weekdayTextColor forKeyPath:@"textColor"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setHeaderTitleFont:(UIFont *)font
|
||||
{
|
||||
if (![_headerTitleFont isEqual:font]) {
|
||||
_headerTitleFont = font;
|
||||
_header.titleFont = font;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setHeaderTitleColor:(UIColor *)color
|
||||
{
|
||||
if (![_headerTitleColor isEqual:color]) {
|
||||
_headerTitleColor = color;
|
||||
_header.titleColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setHeaderDateFormat:(NSString *)dateFormat
|
||||
{
|
||||
_header.dateFormat = dateFormat;
|
||||
}
|
||||
|
||||
- (NSString *)headerDateFormat
|
||||
{
|
||||
return _header.dateFormat;
|
||||
}
|
||||
|
||||
- (void)setHeaderHeight:(CGFloat)headerHeight
|
||||
{
|
||||
if (_headerHeight != headerHeight) {
|
||||
|
|
@ -488,260 +436,14 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void)setAutoAdjustTitleSize:(BOOL)autoAdjustTitleSize
|
||||
{
|
||||
if (_autoAdjustTitleSize != autoAdjustTitleSize) {
|
||||
_autoAdjustTitleSize = autoAdjustTitleSize;
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Colors
|
||||
|
||||
- (void)setTitleDefaultColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_titleColors[@(FSCalendarCellStateNormal)] = color;
|
||||
} else {
|
||||
[_titleColors removeObjectForKey:@(FSCalendarCellStateNormal)];
|
||||
}
|
||||
[_collectionView.visibleCells setValue:_titleColors forKey:@"titleColors"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)titleDefaultColor
|
||||
{
|
||||
return _titleColors[@(FSCalendarCellStateNormal)];
|
||||
}
|
||||
|
||||
- (void)setTitleSelectionColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_titleColors[@(FSCalendarCellStateSelected)] = color;
|
||||
} else {
|
||||
[_titleColors removeObjectForKey:@(FSCalendarCellStateSelected)];
|
||||
}
|
||||
[_collectionView.visibleCells setValue:_titleColors forKey:@"titleColors"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)titleSelectionColor
|
||||
{
|
||||
return _titleColors[@(FSCalendarCellStateSelected)];
|
||||
}
|
||||
|
||||
- (void)setTitleTodayColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_titleColors[@(FSCalendarCellStateToday)] = color;
|
||||
} else {
|
||||
[_titleColors removeObjectForKey:@(FSCalendarCellStateToday)];
|
||||
}
|
||||
[_collectionView.visibleCells setValue:_titleColors forKey:@"titleColors"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)titleTodayColor
|
||||
{
|
||||
return _titleColors[@(FSCalendarCellStateToday)];
|
||||
}
|
||||
|
||||
- (void)setTitlePlaceholderColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_titleColors[@(FSCalendarCellStatePlaceholder)] = color;
|
||||
} else {
|
||||
[_titleColors removeObjectForKey:@(FSCalendarCellStatePlaceholder)];
|
||||
}
|
||||
[_collectionView.visibleCells setValue:_titleColors forKey:@"titleColors"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)titlePlaceholderColor
|
||||
{
|
||||
return _titleColors[@(FSCalendarCellStatePlaceholder)];
|
||||
}
|
||||
|
||||
- (void)setTitleWeekendColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_titleColors[@(FSCalendarCellStateWeekend)] = color;
|
||||
} else {
|
||||
[_titleColors removeObjectForKey:@(FSCalendarCellStateWeekend)];
|
||||
}
|
||||
[_collectionView.visibleCells setValue:_titleColors forKey:@"titleColors"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)titleWeekendColor
|
||||
{
|
||||
return _titleColors[@(FSCalendarCellStateWeekend)];
|
||||
}
|
||||
|
||||
- (void)setSubtitleDefaultColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_subtitleColors[@(FSCalendarCellStateNormal)] = color;
|
||||
} else {
|
||||
[_subtitleColors removeObjectForKey:@(FSCalendarCellStateNormal)];
|
||||
}
|
||||
[_collectionView.visibleCells setValue:_subtitleColors forKey:@"subtitleColors"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
-(UIColor *)subtitleDefaultColor
|
||||
{
|
||||
return _subtitleColors[@(FSCalendarCellStateNormal)];
|
||||
}
|
||||
|
||||
- (void)setSubtitleSelectionColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_subtitleColors[@(FSCalendarCellStateSelected)] = color;
|
||||
} else {
|
||||
[_subtitleColors removeObjectForKey:@(FSCalendarCellStateSelected)];
|
||||
}
|
||||
[_collectionView.visibleCells setValue:_subtitleColors forKey:@"subtitleColors"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)subtitleSelectionColor
|
||||
{
|
||||
return _subtitleColors[@(FSCalendarCellStateSelected)];
|
||||
}
|
||||
|
||||
- (void)setSubtitleTodayColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_subtitleColors[@(FSCalendarCellStateToday)] = color;
|
||||
} else {
|
||||
[_subtitleColors removeObjectForKey:@(FSCalendarCellStateToday)];
|
||||
}
|
||||
[_collectionView.visibleCells setValue:_subtitleColors forKey:@"subtitleColors"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)subtitleTodayColor
|
||||
{
|
||||
return _subtitleColors[@(FSCalendarCellStateToday)];
|
||||
}
|
||||
|
||||
- (void)setSubtitlePlaceholderColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_subtitleColors[@(FSCalendarCellStatePlaceholder)] = color;
|
||||
} else {
|
||||
[_subtitleColors removeObjectForKey:@(FSCalendarCellStatePlaceholder)];
|
||||
}
|
||||
[_collectionView.visibleCells setValue:_subtitleColors forKey:@"subtitleColors"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)subtitlePlaceholderColor
|
||||
{
|
||||
return _subtitleColors[@(FSCalendarCellStatePlaceholder)];
|
||||
}
|
||||
|
||||
- (void)setSubtitleWeekendColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_subtitleColors[@(FSCalendarCellStateWeekend)] = color;
|
||||
} else {
|
||||
[_subtitleColors removeObjectForKey:@(FSCalendarCellStateWeekend)];
|
||||
}
|
||||
[_collectionView.visibleCells setValue:_subtitleColors forKey:@"subtitleColors"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)subtitleWeekendColor
|
||||
{
|
||||
return _subtitleColors[@(FSCalendarCellStateWeekend)];
|
||||
}
|
||||
|
||||
- (void)setSelectionColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_backgroundColors[@(FSCalendarCellStateSelected)] = color;
|
||||
} else {
|
||||
[_backgroundColors removeObjectForKey:@(FSCalendarCellStateSelected)];
|
||||
}
|
||||
[_collectionView.visibleCells setValue:_backgroundColors forKey:@"backgroundColors"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)selectionColor
|
||||
{
|
||||
return _backgroundColors[@(FSCalendarCellStateSelected)];
|
||||
}
|
||||
|
||||
- (void)setTodayColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_backgroundColors[@(FSCalendarCellStateToday)] = color;
|
||||
} else {
|
||||
[_backgroundColors removeObjectForKey:@(FSCalendarCellStateToday)];
|
||||
}
|
||||
[_collectionView.visibleCells setValue:_backgroundColors forKey:@"backgroundColors"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)todayColor
|
||||
{
|
||||
return _backgroundColors[@(FSCalendarCellStateToday)];
|
||||
}
|
||||
|
||||
- (void)setEventColor:(UIColor *)eventColor
|
||||
{
|
||||
if (![_eventColor isEqual:eventColor]) {
|
||||
_eventColor = eventColor;
|
||||
[_collectionView.visibleCells setValue:_eventColor forKey:@"eventColor"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTitleFont:(UIFont *)font
|
||||
{
|
||||
if (_titleFont != font) {
|
||||
_titleFont = font;
|
||||
if (_autoAdjustTitleSize) {
|
||||
return;
|
||||
}
|
||||
[_collectionView.visibleCells setValue:font forKey:@"titleFont"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setSubtitleFont:(UIFont *)font
|
||||
{
|
||||
if (_subtitleFont != font) {
|
||||
_subtitleFont = font;
|
||||
if (_autoAdjustTitleSize) {
|
||||
return;
|
||||
}
|
||||
[_collectionView.visibleCells setValue:font forKey:@"subtitleFont"];
|
||||
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setMinDissolvedAlpha:(CGFloat)minDissolvedAlpha
|
||||
{
|
||||
if (_minDissolvedAlpha != minDissolvedAlpha) {
|
||||
_minDissolvedAlpha = minDissolvedAlpha;
|
||||
_header.minDissolveAlpha = minDissolvedAlpha;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Public
|
||||
|
||||
- (void)reloadData
|
||||
{
|
||||
|
||||
_header.scrollDirection = self.collectionViewFlowLayout.scrollDirection;
|
||||
_header.titleColor = _headerTitleColor;
|
||||
_header.titleFont = _headerTitleFont;
|
||||
[_header reloadData];
|
||||
|
||||
[_weekdays setValue:_weekdayFont forKey:@"font"];
|
||||
[_weekdays setValue:_appearance.weekdayFont forKey:@"font"];
|
||||
CGFloat width = self.fs_width/_weekdays.count;
|
||||
CGFloat height = kWeekHeight;
|
||||
[_weekdays enumerateObjectsUsingBlock:^(UILabel *weekdayLabel, NSUInteger idx, BOOL *stop) {
|
||||
|
|
@ -826,24 +528,6 @@
|
|||
return [NSIndexPath indexPathForItem:item inSection:section];
|
||||
}
|
||||
|
||||
- (void)adjustTitleIfNecessary
|
||||
{
|
||||
if (_autoAdjustTitleSize) {
|
||||
self.titleFont = [_titleFont fontWithSize:_collectionView.fs_height/3/6];
|
||||
self.subtitleFont = [_subtitleFont fontWithSize:_collectionView.fs_height/4.5/6];
|
||||
self.headerTitleFont = [_headerTitleFont fontWithSize:_titleFont.pointSize+3];
|
||||
self.weekdayFont = _titleFont;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setCellStyle:(FSCalendarCellStyle)cellStyle
|
||||
{
|
||||
if (_cellStyle != cellStyle) {
|
||||
_cellStyle = cellStyle;
|
||||
[self reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)isDateInRange:(NSDate *)date
|
||||
{
|
||||
return [date fs_daysFrom:self.minimumDate] >= 0 && [date fs_daysFrom:self.maximumDate] <= 0;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// FSCalendarAppearance.h
|
||||
// Pods
|
||||
//
|
||||
// Created by DingWenchao on 6/29/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
typedef NS_OPTIONS(NSInteger, FSCalendarCellStyle) {
|
||||
FSCalendarCellStyleCircle = 0,
|
||||
FSCalendarCellStyleRectangle = 1
|
||||
};
|
||||
|
||||
@class FSCalendar;
|
||||
|
||||
@interface FSCalendarAppearance : NSObject
|
||||
|
||||
@property (weak , nonatomic) FSCalendar *calendar;
|
||||
|
||||
@property (strong, nonatomic) UIFont *titleFont;
|
||||
@property (strong, nonatomic) UIFont *subtitleFont;
|
||||
@property (strong, nonatomic) UIFont *weekdayFont;
|
||||
@property (strong, nonatomic) UIColor *eventColor;
|
||||
@property (strong, nonatomic) UIColor *weekdayTextColor;
|
||||
|
||||
@property (strong, nonatomic) UIColor *headerTitleColor;
|
||||
@property (strong, nonatomic) NSString *headerDateFormat;
|
||||
@property (strong, nonatomic) UIFont *headerTitleFont;
|
||||
@property (assign, nonatomic) CGFloat headerMinimumDissolvedAlpha;
|
||||
|
||||
@property (strong, nonatomic) UIColor *titleDefaultColor;
|
||||
@property (strong, nonatomic) UIColor *titleSelectionColor;
|
||||
@property (strong, nonatomic) UIColor *titleTodayColor;
|
||||
@property (strong, nonatomic) UIColor *titlePlaceholderColor;
|
||||
@property (strong, nonatomic) UIColor *titleWeekendColor;
|
||||
|
||||
@property (strong, nonatomic) UIColor *subtitleDefaultColor;
|
||||
@property (strong, nonatomic) UIColor *subtitleSelectionColor;
|
||||
@property (strong, nonatomic) UIColor *subtitleTodayColor;
|
||||
@property (strong, nonatomic) UIColor *subtitlePlaceholderColor;
|
||||
@property (strong, nonatomic) UIColor *subtitleWeekendColor;
|
||||
|
||||
@property (strong, nonatomic) UIColor *selectionColor;
|
||||
@property (strong, nonatomic) UIColor *todayColor;
|
||||
|
||||
@property (assign, nonatomic) FSCalendarCellStyle cellStyle;
|
||||
@property (assign, nonatomic) BOOL autoAdjustTitleSize;
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,356 @@
|
|||
//
|
||||
// FSCalendarAppearance.m
|
||||
// Pods
|
||||
//
|
||||
// Created by DingWenchao on 6/29/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import "FSCalendarAppearance.h"
|
||||
#import "FSCalendarDynamicHeader.h"
|
||||
#import "UIView+FSExtension.h"
|
||||
|
||||
#define kBlueText [UIColor colorWithRed:14/255.0 green:69/255.0 blue:221/255.0 alpha:1.0]
|
||||
#define kPink [UIColor colorWithRed:198/255.0 green:51/255.0 blue:42/255.0 alpha:1.0]
|
||||
#define kBlue [UIColor colorWithRed:31/255.0 green:119/255.0 blue:219/255.0 alpha:1.0]
|
||||
|
||||
@interface FSCalendarAppearance ()
|
||||
|
||||
@property (strong, nonatomic) NSMutableDictionary *backgroundColors;
|
||||
@property (strong, nonatomic) NSMutableDictionary *titleColors;
|
||||
@property (strong, nonatomic) NSMutableDictionary *subtitleColors;
|
||||
|
||||
- (void)adjustTitleIfNecessary;
|
||||
|
||||
@end
|
||||
|
||||
@implementation FSCalendarAppearance
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
|
||||
_autoAdjustTitleSize = YES;
|
||||
|
||||
_titleFont = [UIFont systemFontOfSize:15];
|
||||
_subtitleFont = [UIFont systemFontOfSize:10];
|
||||
_weekdayFont = [UIFont systemFontOfSize:15];
|
||||
_headerTitleFont = [UIFont systemFontOfSize:15];
|
||||
_headerTitleColor = kBlueText;
|
||||
_headerDateFormat = @"MMMM yyyy";
|
||||
_headerMinimumDissolvedAlpha = 0.2;
|
||||
_weekdayTextColor = kBlueText;
|
||||
|
||||
_backgroundColors = [NSMutableDictionary dictionaryWithCapacity:4];
|
||||
_backgroundColors[@(FSCalendarCellStateNormal)] = [UIColor clearColor];
|
||||
_backgroundColors[@(FSCalendarCellStateSelected)] = kBlue;
|
||||
_backgroundColors[@(FSCalendarCellStateDisabled)] = [UIColor clearColor];
|
||||
_backgroundColors[@(FSCalendarCellStatePlaceholder)] = [UIColor clearColor];
|
||||
_backgroundColors[@(FSCalendarCellStateToday)] = kPink;
|
||||
|
||||
_titleColors = [NSMutableDictionary dictionaryWithCapacity:4];
|
||||
_titleColors[@(FSCalendarCellStateNormal)] = [UIColor darkTextColor];
|
||||
_titleColors[@(FSCalendarCellStateSelected)] = [UIColor whiteColor];
|
||||
_titleColors[@(FSCalendarCellStateDisabled)] = [UIColor grayColor];
|
||||
_titleColors[@(FSCalendarCellStatePlaceholder)] = [UIColor lightGrayColor];
|
||||
_titleColors[@(FSCalendarCellStateToday)] = [UIColor whiteColor];
|
||||
|
||||
_subtitleColors = [NSMutableDictionary dictionaryWithCapacity:4];
|
||||
_subtitleColors[@(FSCalendarCellStateNormal)] = [UIColor darkGrayColor];
|
||||
_subtitleColors[@(FSCalendarCellStateSelected)] = [UIColor whiteColor];
|
||||
_subtitleColors[@(FSCalendarCellStateDisabled)] = [UIColor lightGrayColor];
|
||||
_subtitleColors[@(FSCalendarCellStatePlaceholder)] = [UIColor lightGrayColor];
|
||||
_subtitleColors[@(FSCalendarCellStateToday)] = [UIColor whiteColor];
|
||||
|
||||
_cellStyle = FSCalendarCellStyleCircle;
|
||||
_eventColor = [kBlue colorWithAlphaComponent:0.75];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)setTitleDefaultColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_titleColors[@(FSCalendarCellStateNormal)] = color;
|
||||
} else {
|
||||
[_titleColors removeObjectForKey:@(FSCalendarCellStateNormal)];
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)titleDefaultColor
|
||||
{
|
||||
return _titleColors[@(FSCalendarCellStateNormal)];
|
||||
}
|
||||
|
||||
- (void)setTitleSelectionColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_titleColors[@(FSCalendarCellStateSelected)] = color;
|
||||
} else {
|
||||
[_titleColors removeObjectForKey:@(FSCalendarCellStateSelected)];
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)titleSelectionColor
|
||||
{
|
||||
return _titleColors[@(FSCalendarCellStateSelected)];
|
||||
}
|
||||
|
||||
- (void)setTitleTodayColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_titleColors[@(FSCalendarCellStateToday)] = color;
|
||||
} else {
|
||||
[_titleColors removeObjectForKey:@(FSCalendarCellStateToday)];
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)titleTodayColor
|
||||
{
|
||||
return _titleColors[@(FSCalendarCellStateToday)];
|
||||
}
|
||||
|
||||
- (void)setTitlePlaceholderColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_titleColors[@(FSCalendarCellStatePlaceholder)] = color;
|
||||
} else {
|
||||
[_titleColors removeObjectForKey:@(FSCalendarCellStatePlaceholder)];
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)titlePlaceholderColor
|
||||
{
|
||||
return _titleColors[@(FSCalendarCellStatePlaceholder)];
|
||||
}
|
||||
|
||||
- (void)setTitleWeekendColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_titleColors[@(FSCalendarCellStateWeekend)] = color;
|
||||
} else {
|
||||
[_titleColors removeObjectForKey:@(FSCalendarCellStateWeekend)];
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)titleWeekendColor
|
||||
{
|
||||
return _titleColors[@(FSCalendarCellStateWeekend)];
|
||||
}
|
||||
|
||||
- (void)setSubtitleDefaultColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_subtitleColors[@(FSCalendarCellStateNormal)] = color;
|
||||
} else {
|
||||
[_subtitleColors removeObjectForKey:@(FSCalendarCellStateNormal)];
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
-(UIColor *)subtitleDefaultColor
|
||||
{
|
||||
return _subtitleColors[@(FSCalendarCellStateNormal)];
|
||||
}
|
||||
|
||||
- (void)setSubtitleSelectionColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_subtitleColors[@(FSCalendarCellStateSelected)] = color;
|
||||
} else {
|
||||
[_subtitleColors removeObjectForKey:@(FSCalendarCellStateSelected)];
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)subtitleSelectionColor
|
||||
{
|
||||
return _subtitleColors[@(FSCalendarCellStateSelected)];
|
||||
}
|
||||
|
||||
- (void)setSubtitleTodayColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_subtitleColors[@(FSCalendarCellStateToday)] = color;
|
||||
} else {
|
||||
[_subtitleColors removeObjectForKey:@(FSCalendarCellStateToday)];
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)subtitleTodayColor
|
||||
{
|
||||
return _subtitleColors[@(FSCalendarCellStateToday)];
|
||||
}
|
||||
|
||||
- (void)setSubtitlePlaceholderColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_subtitleColors[@(FSCalendarCellStatePlaceholder)] = color;
|
||||
} else {
|
||||
[_subtitleColors removeObjectForKey:@(FSCalendarCellStatePlaceholder)];
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)subtitlePlaceholderColor
|
||||
{
|
||||
return _subtitleColors[@(FSCalendarCellStatePlaceholder)];
|
||||
}
|
||||
|
||||
- (void)setSubtitleWeekendColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_subtitleColors[@(FSCalendarCellStateWeekend)] = color;
|
||||
} else {
|
||||
[_subtitleColors removeObjectForKey:@(FSCalendarCellStateWeekend)];
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)subtitleWeekendColor
|
||||
{
|
||||
return _subtitleColors[@(FSCalendarCellStateWeekend)];
|
||||
}
|
||||
|
||||
- (void)setSelectionColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_backgroundColors[@(FSCalendarCellStateSelected)] = color;
|
||||
} else {
|
||||
[_backgroundColors removeObjectForKey:@(FSCalendarCellStateSelected)];
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)selectionColor
|
||||
{
|
||||
return _backgroundColors[@(FSCalendarCellStateSelected)];
|
||||
}
|
||||
|
||||
- (void)setTodayColor:(UIColor *)color
|
||||
{
|
||||
if (color) {
|
||||
_backgroundColors[@(FSCalendarCellStateToday)] = color;
|
||||
} else {
|
||||
[_backgroundColors removeObjectForKey:@(FSCalendarCellStateToday)];
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
|
||||
- (UIColor *)todayColor
|
||||
{
|
||||
return _backgroundColors[@(FSCalendarCellStateToday)];
|
||||
}
|
||||
|
||||
- (void)setEventColor:(UIColor *)eventColor
|
||||
{
|
||||
if (![_eventColor isEqual:eventColor]) {
|
||||
_eventColor = eventColor;
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTitleFont:(UIFont *)font
|
||||
{
|
||||
if (_titleFont != font) {
|
||||
_titleFont = font;
|
||||
if (_autoAdjustTitleSize) {
|
||||
return;
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setSubtitleFont:(UIFont *)font
|
||||
{
|
||||
if (_subtitleFont != font) {
|
||||
_subtitleFont = font;
|
||||
if (_autoAdjustTitleSize) {
|
||||
return;
|
||||
}
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setCellStyle:(FSCalendarCellStyle)cellStyle
|
||||
{
|
||||
if (_cellStyle != cellStyle) {
|
||||
_cellStyle = cellStyle;
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)setWeekdayFont:(UIFont *)weekdayFont
|
||||
{
|
||||
if (![_weekdayFont isEqual:weekdayFont]) {
|
||||
_weekdayFont = weekdayFont;
|
||||
[_calendar.weekdays setValue:weekdayFont forKeyPath:@"font"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setWeekdayTextColor:(UIColor *)weekdayTextColor
|
||||
{
|
||||
if (![_weekdayTextColor isEqual:weekdayTextColor]) {
|
||||
_weekdayTextColor = weekdayTextColor;
|
||||
[_calendar.weekdays setValue:weekdayTextColor forKeyPath:@"textColor"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setHeaderTitleFont:(UIFont *)font
|
||||
{
|
||||
if (![_headerTitleFont isEqual:font]) {
|
||||
_headerTitleFont = font;
|
||||
[_calendar.header.collectionView reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setHeaderTitleColor:(UIColor *)color
|
||||
{
|
||||
if (![_headerTitleColor isEqual:color]) {
|
||||
_headerTitleColor = color;
|
||||
[_calendar.header.collectionView reloadData];
|
||||
}
|
||||
}
|
||||
- (void)setAutoAdjustTitleSize:(BOOL)autoAdjustTitleSize
|
||||
{
|
||||
if (_autoAdjustTitleSize != autoAdjustTitleSize) {
|
||||
_autoAdjustTitleSize = autoAdjustTitleSize;
|
||||
[self adjustTitleIfNecessary];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setHeaderMinimumDissolvedAlpha:(CGFloat)headerMinimumDissolvedAlpha
|
||||
{
|
||||
if (_headerMinimumDissolvedAlpha != headerMinimumDissolvedAlpha) {
|
||||
_headerMinimumDissolvedAlpha = headerMinimumDissolvedAlpha;
|
||||
[_calendar.header.collectionView reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)adjustTitleIfNecessary
|
||||
{
|
||||
if (_autoAdjustTitleSize) {
|
||||
_titleFont = [_titleFont fontWithSize:_calendar.collectionView.fs_height/3/6];
|
||||
_subtitleFont = [_subtitleFont fontWithSize:_calendar.collectionView.fs_height/4.5/6];
|
||||
_headerTitleFont = [_headerTitleFont fontWithSize:_titleFont.pointSize+3];
|
||||
_weekdayFont = _titleFont;
|
||||
|
||||
// reload appearance
|
||||
[_calendar.collectionView.visibleCells makeObjectsPerformSelector:@selector(configureCell)];
|
||||
[_calendar.header.collectionView reloadData];
|
||||
[_calendar.weekdays setValue:_weekdayFont forKeyPath:@"font"];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -11,11 +11,7 @@
|
|||
|
||||
@interface FSCalendarCell : UICollectionViewCell
|
||||
|
||||
@property (weak, nonatomic) NSDictionary *titleColors;
|
||||
@property (weak, nonatomic) NSDictionary *subtitleColors;
|
||||
@property (weak, nonatomic) NSDictionary *backgroundColors;
|
||||
|
||||
@property (weak, nonatomic) UIColor *eventColor;
|
||||
@property (weak, nonatomic) FSCalendarAppearance *appearance;
|
||||
|
||||
@property (copy, nonatomic) NSDate *date;
|
||||
@property (copy, nonatomic) NSDate *month;
|
||||
|
|
@ -26,7 +22,6 @@
|
|||
@property (weak, nonatomic) UILabel *titleLabel;
|
||||
@property (weak, nonatomic) UILabel *subtitleLabel;
|
||||
|
||||
@property (assign, nonatomic) FSCalendarCellStyle cellStyle;
|
||||
@property (assign, nonatomic) BOOL hasEvent;
|
||||
|
||||
@property (readonly, getter = isPlaceholder) BOOL placeholder;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#import "FSCalendar.h"
|
||||
#import "UIView+FSExtension.h"
|
||||
#import "NSDate+FSExtension.h"
|
||||
#import "FSCalendarDynamicHeader.h"
|
||||
|
||||
#define kAnimationDuration 0.15
|
||||
|
||||
|
|
@ -90,7 +91,7 @@
|
|||
{
|
||||
_backgroundLayer.hidden = NO;
|
||||
_backgroundLayer.path = [UIBezierPath bezierPathWithOvalInRect:_backgroundLayer.bounds].CGPath;
|
||||
_backgroundLayer.fillColor = [self colorForCurrentStateInDictionary:_backgroundColors].CGColor;
|
||||
_backgroundLayer.fillColor = [self colorForCurrentStateInDictionary:_appearance.backgroundColors].CGColor;
|
||||
CAAnimationGroup *group = [CAAnimationGroup animation];
|
||||
CABasicAnimation *zoomOut = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
|
||||
zoomOut.fromValue = @0.3;
|
||||
|
|
@ -117,11 +118,13 @@
|
|||
|
||||
- (void)configureCell
|
||||
{
|
||||
_titleLabel.font = _appearance.titleFont;
|
||||
_titleLabel.text = [NSString stringWithFormat:@"%@",@(_date.fs_day)];
|
||||
_subtitleLabel.font = _appearance.subtitleFont;
|
||||
_subtitleLabel.text = _subtitle;
|
||||
_titleLabel.textColor = [self colorForCurrentStateInDictionary:_titleColors];
|
||||
_subtitleLabel.textColor = [self colorForCurrentStateInDictionary:_subtitleColors];
|
||||
_backgroundLayer.fillColor = [self colorForCurrentStateInDictionary:_backgroundColors].CGColor;
|
||||
_titleLabel.textColor = [self colorForCurrentStateInDictionary:_appearance.titleColors];
|
||||
_subtitleLabel.textColor = [self colorForCurrentStateInDictionary:_appearance.subtitleColors];
|
||||
_backgroundLayer.fillColor = [self colorForCurrentStateInDictionary:_appearance.backgroundColors].CGColor;
|
||||
|
||||
CGFloat titleHeight = [_titleLabel.text sizeWithAttributes:@{NSFontAttributeName:self.titleLabel.font}].height;
|
||||
if (_subtitleLabel.text) {
|
||||
|
|
@ -142,10 +145,10 @@
|
|||
_subtitleLabel.hidden = YES;
|
||||
}
|
||||
_backgroundLayer.hidden = !self.selected && !self.isToday;
|
||||
_backgroundLayer.path = _cellStyle == FSCalendarCellStyleCircle ?
|
||||
_backgroundLayer.path = _appearance.cellStyle == FSCalendarCellStyleCircle ?
|
||||
[UIBezierPath bezierPathWithOvalInRect:_backgroundLayer.bounds].CGPath :
|
||||
[UIBezierPath bezierPathWithRect:_backgroundLayer.bounds].CGPath;
|
||||
_eventLayer.fillColor = _eventColor.CGColor;
|
||||
_eventLayer.fillColor = _appearance.eventColor.CGColor;
|
||||
_eventLayer.hidden = !_hasEvent;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
//
|
||||
// FSCalendarDynamicHeader.h
|
||||
// Pods
|
||||
//
|
||||
// Created by DingWenchao on 6/29/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "FSCalendar.h"
|
||||
#import "FSCalendarCell.h"
|
||||
#import "FSCalendarHeader.h"
|
||||
|
||||
/**
|
||||
* 动感头文件,仅供框架内部使用。
|
||||
* Private header, don't use it.
|
||||
*/
|
||||
|
||||
@interface FSCalendar (Dynamic)
|
||||
|
||||
@property (readonly, nonatomic) FSCalendarHeader *header;
|
||||
@property (readonly, nonatomic) UICollectionView *collectionView;
|
||||
@property (readonly, nonatomic) NSArray *weekdays;
|
||||
|
||||
@end
|
||||
|
||||
@interface FSCalendarAppearance (Dynamic)
|
||||
|
||||
@property (readonly, nonatomic) NSMutableDictionary *backgroundColors;
|
||||
@property (readonly, nonatomic) NSMutableDictionary *titleColors;
|
||||
@property (readonly, nonatomic) NSMutableDictionary *subtitleColors;
|
||||
|
||||
- (void)adjustTitleIfNecessary;
|
||||
|
||||
@end
|
||||
|
||||
@interface FSCalendarCell (Dynamic)
|
||||
|
||||
- (void)configureCell;
|
||||
|
||||
@end
|
||||
|
||||
@interface FSCalendarHeader (Dynamic)
|
||||
|
||||
@property (readonly, nonatomic) UICollectionView *collectionView;
|
||||
|
||||
@end
|
||||
|
|
@ -8,18 +8,15 @@
|
|||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class FSCalendarHeader, FSCalendar;
|
||||
@class FSCalendarHeader, FSCalendar, FSCalendarAppearance;
|
||||
|
||||
@interface FSCalendarHeader : UIView
|
||||
|
||||
@property (assign , nonatomic) CGFloat minDissolveAlpha;
|
||||
@property (assign , nonatomic) CGFloat scrollOffset;
|
||||
@property (strong , nonatomic) NSString *dateFormat;
|
||||
@property (strong , nonatomic) NSDate *minimumDate;
|
||||
@property (strong , nonatomic) NSDate *maximumDate;
|
||||
|
||||
@property (weak , nonatomic) UIColor *titleColor;
|
||||
@property (weak , nonatomic) UIFont *titleFont;
|
||||
@property (weak, nonatomic) FSCalendarAppearance *appearance;
|
||||
|
||||
@property (assign , nonatomic) UICollectionViewScrollDirection scrollDirection;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,11 +10,9 @@
|
|||
#import "FSCalendar.h"
|
||||
#import "UIView+FSExtension.h"
|
||||
#import "NSDate+FSExtension.h"
|
||||
#import "NSCalendar+FSExtension.h"
|
||||
|
||||
#define kBlueText [UIColor colorWithRed:14/255.0 green:69/255.0 blue:221/255.0 alpha:1.0]
|
||||
|
||||
|
||||
@interface FSCalendarHeader ()<UICollectionViewDataSource,UICollectionViewDelegate>
|
||||
|
||||
@property (copy, nonatomic) NSDateFormatter *dateFormatter;
|
||||
|
|
@ -47,10 +45,7 @@
|
|||
|
||||
- (void)initialize
|
||||
{
|
||||
_dateFormat = @"MMMM yyyy";
|
||||
_dateFormatter = [[NSDateFormatter alloc] init];
|
||||
_dateFormatter.dateFormat = _dateFormat;
|
||||
_minDissolveAlpha = 0.2;
|
||||
_scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
||||
_minimumDate = [NSDate fs_dateWithYear:1970 month:1 day:1];
|
||||
_maximumDate = [NSDate fs_dateWithYear:2099 month:12 day:31];
|
||||
|
|
@ -59,6 +54,7 @@
|
|||
collectionViewFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
||||
collectionViewFlowLayout.minimumInteritemSpacing = 0;
|
||||
collectionViewFlowLayout.minimumLineSpacing = 0;
|
||||
collectionViewFlowLayout.itemSize = CGSizeMake(1, 1);
|
||||
self.collectionViewFlowLayout = collectionViewFlowLayout;
|
||||
|
||||
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_collectionViewFlowLayout];
|
||||
|
|
@ -80,9 +76,6 @@
|
|||
_collectionView.contentInset = UIEdgeInsetsZero;
|
||||
_collectionViewFlowLayout.itemSize = CGSizeMake(self.fs_width * 0.5,
|
||||
_collectionView.fs_height);
|
||||
CGFloat scrollOffset = self.scrollOffset;
|
||||
_scrollOffset = 0;
|
||||
self.scrollOffset = scrollOffset;
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
||||
|
|
@ -98,16 +91,17 @@
|
|||
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
|
||||
UILabel *titleLabel = (UILabel *)[cell viewWithTag:100];
|
||||
UILabel *titleLabel = (UILabel *)[cell.contentView viewWithTag:100];
|
||||
if (!titleLabel) {
|
||||
titleLabel = [[UILabel alloc] initWithFrame:cell.contentView.bounds];
|
||||
titleLabel.tag = 100;
|
||||
titleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
[cell.contentView addSubview:titleLabel];
|
||||
}
|
||||
titleLabel.font = self.titleFont;
|
||||
titleLabel.textColor = self.titleColor;
|
||||
titleLabel.font = _appearance.headerTitleFont;
|
||||
titleLabel.textColor = _appearance.headerTitleColor;
|
||||
NSDate *date = [_minimumDate fs_dateByAddingMonths:indexPath.item];
|
||||
_dateFormatter.dateFormat = _appearance.headerDateFormat;
|
||||
titleLabel.text = [_dateFormatter stringFromDate:date];
|
||||
return cell;
|
||||
}
|
||||
|
|
@ -119,22 +113,6 @@
|
|||
|
||||
#pragma mark - Properties
|
||||
|
||||
- (void)setTitleFont:(UIFont *)titleFont
|
||||
{
|
||||
if (![_titleFont isEqual:titleFont]) {
|
||||
_titleFont = titleFont;
|
||||
[_collectionView reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTitleColor:(UIColor *)titleColor
|
||||
{
|
||||
if (![_titleColor isEqual:titleColor]) {
|
||||
_titleColor = titleColor;
|
||||
[_collectionView reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setScrollOffset:(CGFloat)scrollOffset
|
||||
{
|
||||
if (_scrollOffset != scrollOffset) {
|
||||
|
|
@ -153,23 +131,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void)setDateFormat:(NSString *)dateFormat
|
||||
{
|
||||
if (![_dateFormat isEqualToString:dateFormat]) {
|
||||
_dateFormat = [dateFormat copy];
|
||||
_dateFormatter.dateFormat = dateFormat;
|
||||
[_collectionView reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setMinDissolveAlpha:(CGFloat)minDissolveAlpha
|
||||
{
|
||||
if (_minDissolveAlpha != minDissolveAlpha) {
|
||||
_minDissolveAlpha = minDissolveAlpha;
|
||||
[_collectionView reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setScrollDirection:(UICollectionViewScrollDirection)scrollDirection
|
||||
{
|
||||
if (_scrollDirection != scrollDirection) {
|
||||
|
|
@ -204,11 +165,11 @@
|
|||
if (self.scrollDirection == UICollectionViewScrollDirectionHorizontal) {
|
||||
CGFloat position = [cell convertPoint:CGPointMake(CGRectGetMidX(cell.bounds), CGRectGetMidY(cell.bounds)) toView:self].x;
|
||||
CGFloat center = CGRectGetMidX(self.bounds);
|
||||
cell.contentView.alpha = 1.0 - (1.0-_minDissolveAlpha)*ABS(center-position)/_collectionViewFlowLayout.itemSize.width;
|
||||
cell.contentView.alpha = 1.0 - (1.0-_appearance.headerMinimumDissolvedAlpha)*ABS(center-position)/_collectionViewFlowLayout.itemSize.width;
|
||||
} else {
|
||||
CGFloat position = [cell convertPoint:CGPointMake(CGRectGetMidX(cell.bounds), CGRectGetMidY(cell.bounds)) toView:self].y;
|
||||
CGFloat center = CGRectGetMidY(self.bounds);
|
||||
cell.contentView.alpha = 1.0 - (1.0-_minDissolveAlpha)*ABS(center-position)/_collectionViewFlowLayout.itemSize.height;
|
||||
cell.contentView.alpha = 1.0 - (1.0-_appearance.headerMinimumDissolvedAlpha)*ABS(center-position)/_collectionViewFlowLayout.itemSize.height;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
//
|
||||
// NSCalendar+FSExtension.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Wenchao Ding on 12/3/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSCalendar (FSExtension)
|
||||
|
||||
+ (instancetype)fs_sharedCalendar;
|
||||
|
||||
@end
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
//
|
||||
// NSCalendar+FSExtension.m
|
||||
// Pods
|
||||
//
|
||||
// Created by Wenchao Ding on 12/3/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import "NSCalendar+FSExtension.h"
|
||||
|
||||
@implementation NSCalendar (FSExtension)
|
||||
|
||||
+ (instancetype)fs_sharedCalendar
|
||||
{
|
||||
static id instance;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
instance = [NSCalendar currentCalendar];
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
@property (readonly, nonatomic) NSInteger fs_minute;
|
||||
@property (readonly, nonatomic) NSInteger fs_second;
|
||||
|
||||
@property (readonly, nonatomic) NSDate *fs_dateByIgnoringTimeComponents;
|
||||
@property (readonly, nonatomic) NSInteger fs_numberOfDaysInMonth;
|
||||
|
||||
- (NSDate *)fs_dateByAddingYears:(NSInteger)years;
|
||||
|
|
@ -44,3 +45,11 @@
|
|||
+ (instancetype)fs_dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSCalendar (FSExtension)
|
||||
|
||||
+ (instancetype)fs_sharedCalendar;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
//
|
||||
|
||||
#import "NSDate+FSExtension.h"
|
||||
#import "NSCalendar+FSExtension.h"
|
||||
|
||||
@implementation NSDate (FSExtension)
|
||||
|
||||
|
|
@ -72,6 +71,13 @@
|
|||
return component.second;
|
||||
}
|
||||
|
||||
- (NSDate *)fs_dateByIgnoringTimeComponents
|
||||
{
|
||||
NSCalendar *c = [NSCalendar fs_sharedCalendar];
|
||||
NSDateComponents *components = [c components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:self];
|
||||
return [c dateFromComponents:components];
|
||||
}
|
||||
|
||||
- (NSInteger)fs_numberOfDaysInMonth
|
||||
{
|
||||
NSCalendar *c = [NSCalendar fs_sharedCalendar];
|
||||
|
|
@ -216,3 +222,19 @@
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSCalendar (FSExtension)
|
||||
|
||||
+ (instancetype)fs_sharedCalendar
|
||||
{
|
||||
static id instance;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
instance = [NSCalendar currentCalendar];
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue