diff --git a/Example/Base.lproj/Main_iPhone.storyboard b/Example/Base.lproj/Main_iPhone.storyboard index 1016da8..0d43bf2 100644 --- a/Example/Base.lproj/Main_iPhone.storyboard +++ b/Example/Base.lproj/Main_iPhone.storyboard @@ -33,9 +33,33 @@ - + + + + + + + + + + + + + @@ -47,8 +71,8 @@ - - + @@ -82,7 +106,7 @@ - + @@ -102,7 +126,7 @@ - + @@ -122,7 +146,7 @@ - + @@ -138,20 +162,27 @@ - - + + - @@ -337,7 +368,7 @@ - + diff --git a/Example/DelegateAppearanceViewController.h b/Example/DelegateAppearanceViewController.h new file mode 100644 index 0000000..0282d99 --- /dev/null +++ b/Example/DelegateAppearanceViewController.h @@ -0,0 +1,16 @@ +// +// DelegateAppearanceViewController.h +// FSCalendar +// +// Created by Wenchao Ding on 10/2/15. +// Copyright © 2015 wenchaoios. All rights reserved. +// + +#import +#import "FSCalendar.h" + +@interface DelegateAppearanceViewController : UIViewController + +@property (weak, nonatomic) FSCalendar *calendar; + +@end diff --git a/Example/DelegateAppearanceViewController.m b/Example/DelegateAppearanceViewController.m new file mode 100644 index 0000000..ac31775 --- /dev/null +++ b/Example/DelegateAppearanceViewController.m @@ -0,0 +1,80 @@ +// +// DelegateAppearanceViewController.m +// FSCalendar +// +// Created by Wenchao Ding on 10/2/15. +// Copyright © 2015 wenchaoios. All rights reserved. +// + +#import "DelegateAppearanceViewController.h" +#import "FSCalendarTestMacros.h" +#import "NSDate+FSExtension.h" + +#define kPink [UIColor colorWithRed:198/255.0 green:51/255.0 blue:42/255.0 alpha:1.0] + +@implementation DelegateAppearanceViewController + +- (instancetype)init +{ + self = [super init]; + if (self) { + self.title = @"FSCalendar"; + } + return self; +} + +- (void)loadView +{ + UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; + view.backgroundColor = [UIColor colorWithRed:.95 green:.95 blue:.95 alpha:1.0]; + self.view = view; + + FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, 300)]; + calendar.backgroundColor = [UIColor whiteColor]; + calendar.dataSource = self; + calendar.delegate = self; + calendar.allowsMultipleSelection = YES; + [self.view addSubview:calendar]; + self.calendar = calendar; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + for (int i = 1; i < 28; i+=2) { + [_calendar selectDate:[[NSDate date].fs_firstDayOfMonth fs_dateByAddingDays:i]]; + } + +#if 0 + FSCalendarTestSelectDate +#endif + +} + +- (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance selectionColorForDate:(NSDate *)date +{ + if (date.fs_day % 5 == 0) { + return [UIColor purpleColor]; + } + if (date.fs_day % 3 == 0) { + return [UIColor cyanColor]; + } + if (date.fs_day % 7 == 0) { + return kPink; + } + return nil; +} + +- (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance titleSelectionColorForDate:(NSDate *)date +{ + if (date.fs_day % 5 == 0) { + return [UIColor orangeColor]; + } + if (date.fs_day % 3 == 0) { + return [UIColor purpleColor]; + } + return nil; +} + +@end diff --git a/Example/FSCalendar.xcodeproj/project.pbxproj b/Example/FSCalendar.xcodeproj/project.pbxproj index c91691f..4942ceb 100644 --- a/Example/FSCalendar.xcodeproj/project.pbxproj +++ b/Example/FSCalendar.xcodeproj/project.pbxproj @@ -69,6 +69,7 @@ EE89AF9E1B9162B90001B657 /* NSString+FSExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = EE89AF9C1B9162B90001B657 /* NSString+FSExtension.h */; settings = {ATTRIBUTES = (Private, ); }; }; EE89AF9F1B9162B90001B657 /* NSString+FSExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = EE89AF9D1B9162B90001B657 /* NSString+FSExtension.m */; }; EE89AFA01B9162B90001B657 /* NSString+FSExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = EE89AF9D1B9162B90001B657 /* NSString+FSExtension.m */; }; + EE90434B1BBEC32800E50992 /* DelegateAppearanceViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EE90434A1BBEC32800E50992 /* DelegateAppearanceViewController.m */; settings = {ASSET_TAGS = (); }; }; EECA10F81BA9C0E400945B83 /* FullScreenExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EECA10F71BA9C0E400945B83 /* FullScreenExampleViewController.m */; }; /* End PBXBuildFile section */ @@ -178,6 +179,8 @@ EE638CF51B8A1F550006DD1A /* FSCalendarTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FSCalendarTests.m; sourceTree = ""; }; EE89AF9C1B9162B90001B657 /* NSString+FSExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+FSExtension.h"; sourceTree = ""; }; EE89AF9D1B9162B90001B657 /* NSString+FSExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+FSExtension.m"; sourceTree = ""; }; + EE9043491BBEC32800E50992 /* DelegateAppearanceViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DelegateAppearanceViewController.h; sourceTree = SOURCE_ROOT; }; + EE90434A1BBEC32800E50992 /* DelegateAppearanceViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DelegateAppearanceViewController.m; sourceTree = SOURCE_ROOT; }; EECA10F61BA9C0E400945B83 /* FullScreenExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FullScreenExampleViewController.h; sourceTree = SOURCE_ROOT; }; EECA10F71BA9C0E400945B83 /* FullScreenExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FullScreenExampleViewController.m; sourceTree = SOURCE_ROOT; }; EEF1EB571BBCBBC600F1B357 /* FSCalendarSelectDateTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSCalendarSelectDateTest.h; sourceTree = SOURCE_ROOT; }; @@ -280,6 +283,7 @@ EE638CD01B89DBE90006DD1A /* AppDelegate.m */, EE638CD11B89DBE90006DD1A /* FSTableViewController.h */, EE638CD21B89DBE90006DD1A /* FSTableViewController.m */, + EE9043481BBEC2D500E50992 /* DelegateAppearance Example */, EECA10F51BA9BF9B00945B83 /* Fullscreen Example */, 30F5D8571B9FC48C00C1C201 /* MultipleSelection Example */, EE52AE151B91E65D00016662 /* FSCalendarScope Example */, @@ -393,6 +397,15 @@ name = "Supporting Files"; sourceTree = ""; }; + EE9043481BBEC2D500E50992 /* DelegateAppearance Example */ = { + isa = PBXGroup; + children = ( + EE9043491BBEC32800E50992 /* DelegateAppearanceViewController.h */, + EE90434A1BBEC32800E50992 /* DelegateAppearanceViewController.m */, + ); + name = "DelegateAppearance Example"; + sourceTree = ""; + }; EECA10F51BA9BF9B00945B83 /* Fullscreen Example */ = { isa = PBXGroup; children = ( @@ -560,6 +573,7 @@ EE638CB31B89DB450006DD1A /* libLunar.c in Sources */, EE638CBA1B89DB450006DD1A /* SSHolidayUK.m in Sources */, EE638CC61B89DB7D0006DD1A /* ViewDidLoadExampleViewController.m in Sources */, + EE90434B1BBEC32800E50992 /* DelegateAppearanceViewController.m in Sources */, EE638CB91B89DB450006DD1A /* SSHolidayTW.m in Sources */, 30B0BACF1B8D8E23004B9476 /* FSCalendar+IBExtension.m in Sources */, EE638CBE1B89DB450006DD1A /* SSLunarDateFormatter.m in Sources */, diff --git a/Example/FSCalendarScopeExampleViewController.m b/Example/FSCalendarScopeExampleViewController.m index 9877910..a9ca048 100644 --- a/Example/FSCalendarScopeExampleViewController.m +++ b/Example/FSCalendarScopeExampleViewController.m @@ -15,6 +15,7 @@ { [super viewDidLoad]; // _calendar.scrollDirection = FSCalendarScrollDirectionVertical; + _calendar.firstWeekday = 1; } - (void)calendarCurrentScopeWillChange:(FSCalendar *)calendar animated:(BOOL)animated diff --git a/Example/FSTableViewController.m b/Example/FSTableViewController.m index 2726c0c..7a87740 100644 --- a/Example/FSTableViewController.m +++ b/Example/FSTableViewController.m @@ -11,6 +11,7 @@ #import "ViewDidLoadExampleViewController.h" #import "MultipleSelectionViewController.h" #import "FullScreenExampleViewController.h" +#import "DelegateAppearanceViewController.h" @implementation FSTableViewController @@ -23,25 +24,28 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { - FullScreenExampleViewController *viewController = [[FullScreenExampleViewController alloc] init]; + DelegateAppearanceViewController *viewController = [[DelegateAppearanceViewController alloc] init]; [self.navigationController pushViewController:viewController animated:YES]; } else if (indexPath.row == 1) { - MultipleSelectionViewController *viewController = [[MultipleSelectionViewController alloc] init]; + FullScreenExampleViewController *viewController = [[FullScreenExampleViewController alloc] init]; [self.navigationController pushViewController:viewController animated:YES]; } else if (indexPath.row == 2) { + MultipleSelectionViewController *viewController = [[MultipleSelectionViewController alloc] init]; + [self.navigationController pushViewController:viewController animated:YES]; + } else if (indexPath.row == 3) { // FSCalendarScope Example return; - } else if (indexPath.row == 3) { + } else if (indexPath.row == 4) { // Storyboard Example return; - } else if (indexPath.row == 4) { + } else if (indexPath.row == 5) { // LoadView Example LoadViewExampleViewController *viewController = [[LoadViewExampleViewController alloc] init]; [self.navigationController pushViewController:viewController animated:YES]; - } else if (indexPath.row == 5) { + } else if (indexPath.row == 6) { // ViewDidLoad Example ViewDidLoadExampleViewController *viewController = [[ViewDidLoadExampleViewController alloc] init]; diff --git a/Example/LoadViewExampleViewController.m b/Example/LoadViewExampleViewController.m index 4b49ad8..85cd0df 100644 --- a/Example/LoadViewExampleViewController.m +++ b/Example/LoadViewExampleViewController.m @@ -29,7 +29,7 @@ - (void)loadView { UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - view.backgroundColor = [UIColor whiteColor]; + view.backgroundColor = [UIColor colorWithRed:.95 green:.95 blue:.95 alpha:1.0]; self.view = view; FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 64, view.frame.size.width, 300)]; @@ -37,6 +37,7 @@ calendar.delegate = self; calendar.scrollDirection = FSCalendarScrollDirectionVertical; [calendar selectDate:[NSDate fs_dateWithYear:2015 month:2 day:1]]; + calendar.backgroundColor = [UIColor whiteColor]; [view addSubview:calendar]; self.calendar = calendar; } diff --git a/Example/MultipleSelectionViewController.h b/Example/MultipleSelectionViewController.h index 60ace5e..4f41d72 100644 --- a/Example/MultipleSelectionViewController.h +++ b/Example/MultipleSelectionViewController.h @@ -10,7 +10,7 @@ #import "FSCalendar.h" #import "NSDate+FSExtension.h" -@interface MultipleSelectionViewController : UIViewController +@interface MultipleSelectionViewController : UIViewController @property (weak, nonatomic) FSCalendar *calendar; diff --git a/Example/MultipleSelectionViewController.m b/Example/MultipleSelectionViewController.m index 560f9cc..1259f22 100644 --- a/Example/MultipleSelectionViewController.m +++ b/Example/MultipleSelectionViewController.m @@ -83,20 +83,4 @@ NSLog(@"selected dates is %@",selectedDates); } -- (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance selectionColorForDate:(NSDate *)date -{ - if (date.fs_day % 3 == 0) { - return [UIColor yellowColor]; - } - return nil; -} - -- (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance titleSelectionColorForDate:(NSDate *)date -{ - if (date.fs_day % 3 == 0) { - return [UIColor blueColor]; - } - return nil; -} - @end diff --git a/Example/StoryboardExampleViewController.m b/Example/StoryboardExampleViewController.m index 0e99fba..23107fe 100644 --- a/Example/StoryboardExampleViewController.m +++ b/Example/StoryboardExampleViewController.m @@ -68,7 +68,7 @@ //- (BOOL)calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date //{ -// return date.fs_day == 3; +// return date.fs_day % 5 == 0; //} //- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar diff --git a/FSCalendar.podspec b/FSCalendar.podspec index 36fe47d..55002d8 100644 --- a/FSCalendar.podspec +++ b/FSCalendar.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "FSCalendar" - s.version = "1.4.1" + s.version = "1.5.0" s.summary = "The fastest, most beautiful and most convenient calendar control, https://www.cocoacontrols.com/controls/fscalendar" s.homepage = "https://github.com/WenchaoIOS/FSCalendar" diff --git a/FSCalendar/FSCalendar.h b/FSCalendar/FSCalendar.h index 9a19e86..5b80cb7 100644 --- a/FSCalendar/FSCalendar.h +++ b/FSCalendar/FSCalendar.h @@ -73,7 +73,9 @@ typedef NS_ENUM(NSInteger, FSCalendarCellState) { @optional - (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance selectionColorForDate:(NSDate *)date; +- (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance titleDefaultColorForDate:(NSDate *)date; - (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance titleSelectionColorForDate:(NSDate *)date; +- (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance subtitleDefaultColorForDate:(NSDate *)date; - (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance subtitleSelectionColorForDate:(NSDate *)date; - (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance eventColorForDate:(NSDate *)date; diff --git a/FSCalendar/FSCalendar.m b/FSCalendar/FSCalendar.m index bc4a8f5..5944bc2 100644 --- a/FSCalendar/FSCalendar.m +++ b/FSCalendar/FSCalendar.m @@ -28,7 +28,9 @@ - (NSDate *)maximumDateForCalendar; - (UIColor *)preferedSelectionColorForDate:(NSDate *)date; +- (UIColor *)preferedTitleDefaultColorForDate:(NSDate *)date; - (UIColor *)preferedTitleSelectionColorForDate:(NSDate *)date; +- (UIColor *)preferedSubtitleDefaultColorForDate:(NSDate *)date; - (UIColor *)preferedSubtitleSelectionColorForDate:(NSDate *)date; - (UIColor *)preferedEventColorForDate:(NSDate *)date; @@ -421,8 +423,12 @@ cell.dateIsToday = [cell.date fs_isEqualToDateForDay:_today]; cell.preferedSelectionColor = [self preferedSelectionColorForDate:cell.date]; + cell.preferedTitleDefaultColor = [self preferedTitleDefaultColorForDate:cell.date]; cell.preferedTitleSelectionColor = [self preferedTitleSelectionColorForDate:cell.date]; - if (cell.subtitle) cell.preferedSubtitleSelectionColor = [self preferedSubtitleSelectionColorForDate:cell.date]; + if (cell.subtitle) { + cell.preferedSubtitleDefaultColor = [self preferedSubtitleDefaultColorForDate:cell.date]; + cell.preferedSubtitleSelectionColor = [self preferedSubtitleSelectionColorForDate:cell.date]; + } if (cell.hasEvent) cell.preferedEventColor = [self preferedEventColorForDate:cell.date]; switch (_scope) { @@ -526,12 +532,12 @@ FSCalendarCell *cell = (FSCalendarCell *)[collectionView cellForItemAtIndexPath:indexPath]; if (cell) { _daysContainer.clipsToBounds = NO; -// [cell performDeselecting]; cell.dateIsSelected = NO; [cell setNeedsLayout]; - [_selectedDates removeObject:cell.date]; - [self didDeselectDate:cell.date]; } + NSDate *selectedDate = self.selectedDate; + [_selectedDates removeObject:selectedDate]; + [self didDeselectDate:selectedDate]; } - (BOOL)collectionView:(UICollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath @@ -1283,7 +1289,7 @@ } case FSCalendarScopeWeek: { section = [date fs_weeksFrom:_minimumDate.fs_firstDayOfWeek]; - item = [date fs_daysFrom:date.fs_firstDayOfWeek]; + item = ((date.fs_weekday - _firstWeekday) + 7) % 7; break; } default: { @@ -1457,6 +1463,15 @@ return nil; } +- (UIColor *)preferedTitleDefaultColorForDate:(NSDate *)date +{ + if (self.delegateAppearance && [self.delegateAppearance respondsToSelector:@selector(calendar:appearance:titleDefaultColorForDate:)]) { + UIColor *color = [self.delegateAppearance calendar:self appearance:self.appearance titleDefaultColorForDate:date]; + return color; + } + return nil; +} + - (UIColor *)preferedTitleSelectionColorForDate:(NSDate *)date { if (self.delegateAppearance && [self.delegateAppearance respondsToSelector:@selector(calendar:appearance:titleSelectionColorForDate:)]) { @@ -1466,6 +1481,15 @@ return nil; } +- (UIColor *)preferedSubtitleDefaultColorForDate:(NSDate *)date +{ + if (self.delegateAppearance && [self.delegateAppearance respondsToSelector:@selector(calendar:appearance:subtitleDefaultColorForDate:)]) { + UIColor *color = [self.delegateAppearance calendar:self appearance:self.appearance subtitleDefaultColorForDate:date]; + return color; + } + return nil; +} + - (UIColor *)preferedSubtitleSelectionColorForDate:(NSDate *)date { if (self.delegateAppearance && [self.delegateAppearance respondsToSelector:@selector(calendar:appearance:subtitleSelectionColorForDate:)]) { diff --git a/FSCalendar/FSCalendarCell.h b/FSCalendar/FSCalendarCell.h index e9a85f2..c5d0760 100644 --- a/FSCalendar/FSCalendarCell.h +++ b/FSCalendar/FSCalendarCell.h @@ -34,7 +34,9 @@ @property (readonly, nonatomic) BOOL weekend; @property (strong, nonatomic) UIColor *preferedSelectionColor; +@property (strong, nonatomic) UIColor *preferedTitleDefaultColor; @property (strong, nonatomic) UIColor *preferedTitleSelectionColor; +@property (strong, nonatomic) UIColor *preferedSubtitleDefaultColor; @property (strong, nonatomic) UIColor *preferedSubtitleSelectionColor; @property (strong, nonatomic) UIColor *preferedEventColor; diff --git a/FSCalendar/FSCalendarCell.m b/FSCalendar/FSCalendarCell.m index dd4bb38..0f255ed 100644 --- a/FSCalendar/FSCalendarCell.m +++ b/FSCalendar/FSCalendarCell.m @@ -225,7 +225,7 @@ if (self.dateIsSelected || self.isSelected) { return self.preferedTitleSelectionColor ?: [self colorForCurrentStateInDictionary:_appearance.titleColors]; } - return [self colorForCurrentStateInDictionary:_appearance.titleColors]; + return self.preferedTitleDefaultColor ?: [self colorForCurrentStateInDictionary:_appearance.titleColors]; } - (UIColor *)colorForSubtitleLabel @@ -233,7 +233,7 @@ if (self.dateIsSelected || self.isSelected) { return self.preferedSubtitleSelectionColor ?: [self colorForCurrentStateInDictionary:_appearance.subtitleColors]; } - return [self colorForCurrentStateInDictionary:_appearance.subtitleColors]; + return self.preferedSubtitleDefaultColor ?: [self colorForCurrentStateInDictionary:_appearance.subtitleColors]; } @end diff --git a/FSCalendar/NSDate+FSExtension.m b/FSCalendar/NSDate+FSExtension.m index 9db9a47..608f10d 100644 --- a/FSCalendar/NSDate+FSExtension.m +++ b/FSCalendar/NSDate+FSExtension.m @@ -102,9 +102,8 @@ NSDateComponents *componentsToSubtract = [[NSDateComponents alloc] init]; componentsToSubtract.day = - (weekdayComponents.weekday - calendar.firstWeekday); NSDate *beginningOfWeek = [calendar dateByAddingComponents:componentsToSubtract toDate:self options:0]; - NSDateComponents *components = [calendar components: (NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) - fromDate: beginningOfWeek]; - beginningOfWeek = [calendar dateFromComponents: components]; + NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:beginningOfWeek]; + beginningOfWeek = [calendar dateFromComponents:components]; return beginningOfWeek; } diff --git a/LICENSE b/LICENSE index 3638703..f7e2b48 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015 = +Copyright (c) 2013-2015 FSCalendar (https://github.com/WenchaoIOS/FSCalendar) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/MOREUSAGE.md b/MOREUSAGE.md new file mode 100644 index 0000000..5f16c4e --- /dev/null +++ b/MOREUSAGE.md @@ -0,0 +1,294 @@ +# More usage + +### If you want `FSCalendar` to scroll vertically + +* Objective - c + +```objective-c +_calendar.scrollDirection = FSCalendarScrollDirectionVertical; +``` + +* Swift + +```swift +calendar.scrollDirection = .Vertical +``` + +![fscalendar-vertical](https://cloud.githubusercontent.com/assets/5186464/8448624/384e344c-1ffc-11e5-8b0b-1c3951dab2e1.gif) + +### If you want `FSCalendar` to scroll horizontally (Default) + +* Objective - c + +```objective-c +_calendar.scrollDirection = FSCalendarScrollDirectionHorizontal; // By default +``` + +* Swift + +```swift +calendar.scrollDirection = .Horizontal +``` + +![fscalendar-horizontal](https://cloud.githubusercontent.com/assets/5186464/8448696/059e9acc-1ffd-11e5-8a95-aff6d871c6e1.gif) + +### For week mode + +* Objective - c + +```objective-c +_calendar.scope = FSCalendarScopeWeek; +``` + +* Swift + +```swift +calendar.scope = .Week +``` + +### For month mode + +* Objective - c + +```objective-c +_calendar.scope = FSCalendarScopeMonth; // By default +``` + +* Swift + +```swift +calendar.scope = .Month +``` + +![fscalendarscope](https://cloud.githubusercontent.com/assets/5186464/9562222/b0318d40-4e98-11e5-97dc-1694cbd26a74.gif) + +### To select more than one date + +```objective-c +_calendar.allowsMultipleSelection = YES; +``` + +![fscalendar-mulipleselection](https://cloud.githubusercontent.com/assets/5186464/9751497/368f55f6-56d8-11e5-9af5-0d09ba13f0eb.png) + +### If you want `FSCalendar` to use `Monday` as the first column (or any other weekday) + +```objective-c +_calendar.firstWeekday = 2; +``` + +![fscalendar---monday](https://cloud.githubusercontent.com/assets/5186464/8448782/c92505e4-1ffd-11e5-95c0-9bf3c8bec669.png) + + +### The date format of header can be customized + +```objective-c +_calendar.appearance.headerDateFormat = @"MMM yy"; +``` + +![fscalendar---headerformat](https://cloud.githubusercontent.com/assets/5186464/8449322/15d79168-2003-11e5-997a-06c6721dd807.png) + +### You can define the appearance + +```objective-c +_calendar.appearance.weekdayTextColor = [UIColor redColor]; +_calendar.appearance.headerTitleColor = [UIColor redColor]; +_calendar.appearance.eventColor = [UIColor greenColor]; +_calendar.appearance.selectionColor = [UIColor blueColor]; +_calendar.appearance.todayColor = [UIColor orangeColor]; +_calendar.appearance.todaySelectionColor = [UIColor blackColor]; +``` + +![fscalendar---colors](https://cloud.githubusercontent.com/assets/5186464/8449300/d55d1c7a-2002-11e5-8de6-be04f3783456.png) + +### The day shape doesn't have to be a circle + +* Objective - c +```objective-c +_calendar.appearance.cellStyle = FSCalendarCellStyleRectangle; +``` + +* Swift +```swift +calendar.appearance.cellStyle = .Rectangle +``` + +![fscalendar---rectangle](https://cloud.githubusercontent.com/assets/5186464/8449186/d38ea39c-2001-11e5-99f4-32fcd6120a01.png) + +### `FSCalendar` can show subtitle for each day + +* Objective - c + +```objective-c +// FSCalendarDataSource +- (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date +{ + return yourSubtitle; +} +``` + +* Swift + +```swift +// FSCalendarDataSource +func calendar(calendar: FSCalendar!, subtitleForDate date: NSDate!) -> String! { + return yourSubtitle +} +``` + +![fscalendar---subtitle2](https://cloud.githubusercontent.com/assets/5186464/8449075/b0bb34ee-2000-11e5-9c4a-401bc708d9ea.png) +
+![fscalendar---subtitle1](https://cloud.githubusercontent.com/assets/5186464/8449076/b0be3d88-2000-11e5-9c5d-22ecd325b6cc.png) + +### And event dot for some days + +* Objective - c + +```objective-c +// FSCalendarDataSource +- (BOOL)calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date +{ + return shouldShowEventDot; +} +``` + +* Swift + +```swift +// FSCalendarDataSource +func calendar(calendar: FSCalendar!, hasEventForDate date: NSDate!) -> Bool { + return shouldShowEventDot +} +``` + +### Or image for some days + +* Objective - c + +```objective-c +// FSCalendarDataSource +- (UIImage *)calendar:(FSCalendar *)calendar imageForDate:(NSDate *)date +{ + return anyImage; +} +``` + +* Swift + +```swift +// FSCalendarDataSource +func calendar(calendar: FSCalendar!, imageForDate date: NSDate!) -> UIImage! { + return anyImage +} +``` + +![fscalendar---image](https://cloud.githubusercontent.com/assets/5186464/8449772/e94d3126-2006-11e5-8871-e4f8dbce81ea.png) + +#### There are left and right boundaries + +```objective-c +// FSCalendarDataSource +- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar +{ + return yourMinimumDate; +} + +- (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar +{ + return yourMaximumDate; +} +``` + +### You can do something when a date is selected + +* Objective - c + +```objective-c +// FSCalendarDelegate +- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date +{ + // Do something +} +``` + +* Swift + +```swift +// FSCalendarDelegate +func calendar(calendar: FSCalendar!, didSelectDate date: NSDate!) { + +} + +``` + +### You can prevent it from being selected + +* Objective - c + +```objective-c +// FSCalendarDelegate +- (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date +{ + if ([dateShouldNotBeSelected]) { + return NO; + } + return YES; +} +``` + +* Swift + +```swift +func calendar(calendar: FSCalendar!, shouldSelectDate date: NSDate!) -> Bool { + if dateShouldNotBeSelected { + return false + } + return true +} +``` + + +### You will get notified when `FSCalendar` changes the month + +* Objective - c + +```objective-c +- (void)calendarCurrentMonthDidChange:(FSCalendar *)calendar +{ + // Do something +} +``` + +* Swift + +```swift +func calendarCurrentMonthDidChange(calendar: FSCalendar!) { + // Do something +} +``` + +### `FSCalendar` can be used on `iPad`. +![fscalendar-ipad](https://cloud.githubusercontent.com/assets/5186464/6502151/b4ce3092-c35b-11e4-827a-498d73579d78.jpg) + +### Roll with Interface Builder + +![fscalendar - ibdesignable](https://cloud.githubusercontent.com/assets/5186464/9301716/2e76a2ca-4503-11e5-8450-1fa7aa93e9fd.gif) + + +* `fakeSubtitles` and `fakedSelectedDay` is only used for preview in Interface Builder + +## Known issues + +* What if I don't need the `today` circle? + +```objective-c +_calendar.appearance.todayColor = [UIColor clearColor]; +_calendar.appearance.titleTodayColor = _calendar.appearance.titleDefaultColor; +_calendar.appearance.subtitleTodayColor = _calendar.appearance.subtitleDefaultColor; +``` + +* Can we hide this? +![fscalendar---headeralpha](https://cloud.githubusercontent.com/assets/5186464/8450978/217855ca-2012-11e5-8b97-a9b45ece4e71.png) + +```objective-c +_calendar.appearance.headerMinimumDissolvedAlpha = 0.0; +``` \ No newline at end of file diff --git a/README.md b/README.md index c7819a2..3a2d6d5 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,7 @@ [![Platform](https://img.shields.io/cocoapods/p/FSCalendar.svg?style=flat)](http://cocoadocs.org/docsets/FSCalendar) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) -![fscalendar---takealook](https://cloud.githubusercontent.com/assets/5186464/8448508/0abae54e-1ffb-11e5-9963-c02e4d44a0af.png) -![fscalendar-takealoot-weekmode](https://cloud.githubusercontent.com/assets/5186464/9626369/b9621d4a-518f-11e5-9464-055475d36c42.png) - - +![fscalendar](https://cloud.githubusercontent.com/assets/5186464/10262249/4fabae40-69f2-11e5-97ab-afbacd0a3da2.jpg) # Installation @@ -81,322 +78,18 @@ view.addSubview(calendar) self.calendar = calendar ``` -## More usage +## More Usage +* To view more usage, download the zip file and read the example. +* Or your could refer to [this document](https://github.com/WenchaoIOS/FSCalendar/MOREUSAGE.md) -### If you want `FSCalendar` to scroll vertically +# If you like this repo +* Star this repo. +* Send your calendar screenshot to #2, or the itunes url of the app. -* Objective - c - -```objective-c -_calendar.scrollDirection = FSCalendarScrollDirectionVertical; -``` - -* Swift - -```swift -calendar.scrollDirection = .Vertical -``` - -![fscalendar-vertical](https://cloud.githubusercontent.com/assets/5186464/8448624/384e344c-1ffc-11e5-8b0b-1c3951dab2e1.gif) - -### If you want `FSCalendar` to scroll horizontally (Default) - -* Objective - c - -```objective-c -_calendar.scrollDirection = FSCalendarScrollDirectionHorizontal; // By default -``` - -* Swift - -```swift -calendar.scrollDirection = .Horizontal -``` - -![fscalendar-horizontal](https://cloud.githubusercontent.com/assets/5186464/8448696/059e9acc-1ffd-11e5-8a95-aff6d871c6e1.gif) - -### For week mode - -* Objective - c - -```objective-c -_calendar.scope = FSCalendarScopeWeek; -``` - -* Swift - -```swift -calendar.scope = .Week -``` - -### For month mode - -* Objective - c - -```objective-c -_calendar.scope = FSCalendarScopeMonth; // By default -``` - -* Swift - -```swift -calendar.scope = .Month -``` - -![fscalendarscope](https://cloud.githubusercontent.com/assets/5186464/9562222/b0318d40-4e98-11e5-97dc-1694cbd26a74.gif) - -### To select more than one date - -```objective-c -_calendar.allowsMultipleSelection = YES; -``` - -![fscalendar-mulipleselection](https://cloud.githubusercontent.com/assets/5186464/9751497/368f55f6-56d8-11e5-9af5-0d09ba13f0eb.png) - -### If you want `FSCalendar` to use `Monday` as the first column (or any other weekday) - -```objective-c -_calendar.firstWeekday = 2; -``` - -![fscalendar---monday](https://cloud.githubusercontent.com/assets/5186464/8448782/c92505e4-1ffd-11e5-95c0-9bf3c8bec669.png) - - -### The date format of header can be customized - -```objective-c -_calendar.appearance.headerDateFormat = @"MMM yy"; -``` - -![fscalendar---headerformat](https://cloud.githubusercontent.com/assets/5186464/8449322/15d79168-2003-11e5-997a-06c6721dd807.png) - -### You can define the appearance - -```objective-c -_calendar.appearance.weekdayTextColor = [UIColor redColor]; -_calendar.appearance.headerTitleColor = [UIColor redColor]; -_calendar.appearance.eventColor = [UIColor greenColor]; -_calendar.appearance.selectionColor = [UIColor blueColor]; -_calendar.appearance.todayColor = [UIColor orangeColor]; -_calendar.appearance.todaySelectionColor = [UIColor blackColor]; -``` - -![fscalendar---colors](https://cloud.githubusercontent.com/assets/5186464/8449300/d55d1c7a-2002-11e5-8de6-be04f3783456.png) - -### The day shape doesn't have to be a circle - -* Objective - c -```objective-c -_calendar.appearance.cellStyle = FSCalendarCellStyleRectangle; -``` - -* Swift -```swift -calendar.appearance.cellStyle = .Rectangle -``` - -![fscalendar---rectangle](https://cloud.githubusercontent.com/assets/5186464/8449186/d38ea39c-2001-11e5-99f4-32fcd6120a01.png) - -### `FSCalendar` can show subtitle for each day - -* Objective - c - -```objective-c -// FSCalendarDataSource -- (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date -{ - return yourSubtitle; -} -``` - -* Swift - -```swift -// FSCalendarDataSource -func calendar(calendar: FSCalendar!, subtitleForDate date: NSDate!) -> String! { - return yourSubtitle -} -``` - -![fscalendar---subtitle2](https://cloud.githubusercontent.com/assets/5186464/8449075/b0bb34ee-2000-11e5-9c4a-401bc708d9ea.png) -
-![fscalendar---subtitle1](https://cloud.githubusercontent.com/assets/5186464/8449076/b0be3d88-2000-11e5-9c5d-22ecd325b6cc.png) - -### And event dot for some days - -* Objective - c - -```objective-c -// FSCalendarDataSource -- (BOOL)calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date -{ - return shouldShowEventDot; -} -``` - -* Swift - -```swift -// FSCalendarDataSource -func calendar(calendar: FSCalendar!, hasEventForDate date: NSDate!) -> Bool { - return shouldShowEventDot -} -``` - -### Or image for some days - -* Objective - c - -```objective-c -// FSCalendarDataSource -- (UIImage *)calendar:(FSCalendar *)calendar imageForDate:(NSDate *)date -{ - return anyImage; -} -``` - -* Swift - -```swift -// FSCalendarDataSource -func calendar(calendar: FSCalendar!, imageForDate date: NSDate!) -> UIImage! { - return anyImage -} -``` - -![fscalendar---image](https://cloud.githubusercontent.com/assets/5186464/8449772/e94d3126-2006-11e5-8871-e4f8dbce81ea.png) - -#### There are left and right boundaries - -```objective-c -// FSCalendarDataSource -- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar -{ - return yourMinimumDate; -} - -- (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar -{ - return yourMaximumDate; -} -``` - -### You can do something when a date is selected - -* Objective - c - -```objective-c -// FSCalendarDelegate -- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date -{ - // Do something -} -``` - -* Swift - -```swift -// FSCalendarDelegate -func calendar(calendar: FSCalendar!, didSelectDate date: NSDate!) { - -} - -``` - -### You can prevent it from being selected - -* Objective - c - -```objective-c -// FSCalendarDelegate -- (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date -{ - if ([dateShouldNotBeSelected]) { - return NO; - } - return YES; -} -``` - -* Swift - -```swift -func calendar(calendar: FSCalendar!, shouldSelectDate date: NSDate!) -> Bool { - if dateShouldNotBeSelected { - return false - } - return true -} -``` - - -### You will get notified when `FSCalendar` changes the month - -* Objective - c - -```objective-c -- (void)calendarCurrentMonthDidChange:(FSCalendar *)calendar -{ - // Do something -} -``` - -* Swift - -```swift -func calendarCurrentMonthDidChange(calendar: FSCalendar!) { - // Do something -} -``` - -### `FSCalendar` can be used on `iPad`. -![fscalendar-ipad](https://cloud.githubusercontent.com/assets/5186464/6502151/b4ce3092-c35b-11e4-827a-498d73579d78.jpg) - -### Roll with Interface Builder - -![fscalendar - ibdesignable](https://cloud.githubusercontent.com/assets/5186464/9301716/2e76a2ca-4503-11e5-8450-1fa7aa93e9fd.gif) - - -* `fakeSubtitles` and `fakedSelectedDay` is only used for preview in Interface Builder - -## Known issues -* The title size changed as we change frame size of FSCalendar: Automatically adjusting font size based on frame size is default behavior of FSCalendadr, to disable it: - -```objective-c -_calendar.appearance.autoAdjustTitleSize = NO; -_calendar.appearance.titleFont = otherTitleFont; -_calendar.appearance.subtitleFont = otherSubtitleFont; -``` - -`titleFont` and `subtitleFont` would not take any effect if `autoAdjustTitleSize` value is `YES` - -* What if I don't need the `today` circle? - -```objective-c -_calendar.appearance.todayColor = [UIColor clearColor]; -_calendar.appearance.titleTodayColor = _calendar.appearance.titleDefaultColor; -_calendar.appearance.subtitleTodayColor = _calendar.appearance.subtitleDefaultColor; -``` - -* Can we hide this? -![fscalendar---headeralpha](https://cloud.githubusercontent.com/assets/5186464/8450978/217855ca-2012-11e5-8b97-a9b45ece4e71.png) - -```objective-c -_calendar.appearance.headerMinimumDissolvedAlpha = 0.0; -``` +# Contact me +* Email: `f33chobits@gmail.com` +* Skype: `wenchao.ding` # License - FSCalendar is available under the MIT license. See the LICENSE file for more info. -# Support -* If FSCalendar cannot meet your requirment, tell me in issues or send your pull requests -* If you like this control and use it in your app, submit your app's link address [here](https://www.cocoacontrols.com/controls/fscalendar).It would be a great support. - -# Contact -* email: `f33chobits@gmail.com` -* skype: `wenchao.ding` - -# Donate -* Paypal - f33chobits@gmail.com -