Add full documentation
1. Add full documentation 2. Add ‘nullability’ 3. Update example
This commit is contained in:
parent
e4aaf98c9e
commit
7b605941ab
|
|
@ -36,6 +36,11 @@
|
|||
|
||||
}
|
||||
|
||||
- (void)calendarCurrentPageDidChange:(FSCalendar *)calendar
|
||||
{
|
||||
NSLog(@"%s %@", __FUNCTION__, [calendar stringFromDate:calendar.currentPage]);
|
||||
}
|
||||
|
||||
#pragma mark - <UITableViewDataSource>
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
Pod::Spec.new do |s|
|
||||
|
||||
s.name = "FSCalendar"
|
||||
s.version = "2.0.0"
|
||||
s.version = "2.0.1"
|
||||
s.summary = "Designed to build the best iOS calendar control."
|
||||
|
||||
s.homepage = "https://github.com/WenchaoD/FSCalendar"
|
||||
|
|
|
|||
|
|
@ -12,6 +12,18 @@
|
|||
#import "FSCalendarAppearance.h"
|
||||
#import "FSCalendarConstance.h"
|
||||
|
||||
/**
|
||||
* FSCalendar is a superior awesome calendar control with high performance, high customizablility and very simple usage.
|
||||
*
|
||||
* @warning All NSDate instances used in the calendar should be managed by the DateTools category. See FSCalendar+DateTools.
|
||||
*
|
||||
* @see FSCalendarDataSource
|
||||
* @see FSCalendarDelegate
|
||||
* @see FSCalendarDelegateAppearance
|
||||
* @see FSCalendarAppearance
|
||||
* @see FSCalendar+DateTools
|
||||
*/
|
||||
|
||||
//! Project version number for FSCalendar.
|
||||
FOUNDATION_EXPORT double FSCalendarVersionNumber;
|
||||
|
||||
|
|
@ -34,51 +46,162 @@ typedef NS_ENUM(NSUInteger, FSCalendarUnit) {
|
|||
FSCalendarUnitDay = NSCalendarUnitDay
|
||||
};
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class FSCalendar;
|
||||
|
||||
/**
|
||||
* FSCalendarDataSource is a source set of FSCalendar. The basic job is to provide event、subtitle and min/max day to display for calendar.
|
||||
*/
|
||||
@protocol FSCalendarDataSource <NSObject>
|
||||
|
||||
@optional
|
||||
- (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date;
|
||||
- (UIImage *)calendar:(FSCalendar *)calendar imageForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the dataSource for a subtitle for the specific date under the day text.
|
||||
*/
|
||||
- (nullable NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the dataSource for an image for the specific date.
|
||||
*/
|
||||
- (nullable UIImage *)calendar:(FSCalendar *)calendar imageForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the dataSource the minimum date to display.
|
||||
*/
|
||||
- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar;
|
||||
|
||||
/**
|
||||
* Asks the dataSource the maximum date to display.
|
||||
*/
|
||||
- (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar;
|
||||
|
||||
/**
|
||||
* Asks the dataSource the number of event dots for a specific date.
|
||||
*
|
||||
* @see
|
||||
*
|
||||
* - (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance eventColorForDate:(NSDate *)date;
|
||||
* - (NSArray *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance eventColorsForDate:(NSDate *)date;
|
||||
*/
|
||||
- (NSInteger)calendar:(FSCalendar *)calendar numberOfEventsForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* This function is deprecated
|
||||
*/
|
||||
- (BOOL)calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date FSCalendarDeprecated(-calendar:numberOfEventsForDate:);
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
* The delegate of a FSCalendar object must adopt the FSCalendarDelegate protocol. The optional methods of FSCalendarDelegate manage selections、 user events and help to manager the frame of the calendar.
|
||||
*/
|
||||
@protocol FSCalendarDelegate <NSObject>
|
||||
|
||||
@optional
|
||||
|
||||
/**
|
||||
* Asks the delegate whether the specific date is allowed to be selected by tapping.
|
||||
*/
|
||||
- (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Tells the delegate a date in the calendar is selected by tapping.
|
||||
*/
|
||||
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the delegate whether the specific date is allowed to be deselected by tapping.
|
||||
*/
|
||||
- (BOOL)calendar:(FSCalendar *)calendar shouldDeselectDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Tells the delegate a date in the calendar is deselected by tapping.
|
||||
*/
|
||||
- (void)calendar:(FSCalendar *)calendar didDeselectDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Tells the delegate the calendar is about to change the bounding rect.
|
||||
*/
|
||||
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated;
|
||||
|
||||
/**
|
||||
* Tells the delegate the calendar is about to change the current page.
|
||||
*/
|
||||
- (void)calendarCurrentPageDidChange:(FSCalendar *)calendar;
|
||||
|
||||
/**
|
||||
* These functions are deprecated
|
||||
*/
|
||||
- (void)calendarCurrentScopeWillChange:(FSCalendar *)calendar animated:(BOOL)animated FSCalendarDeprecated(-calendar:boundingRectWillChange:animated:);
|
||||
- (void)calendarCurrentMonthDidChange:(FSCalendar *)calendar FSCalendarDeprecated(-calendarCurrentPageDidChange:);
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* FSCalendarDelegateAppearance determines the fonts and colors of components in the calendar, but more specificly. Basely, if you need to make a global customization of appearance of the calendar, use FSCalendarAppearance. But if you need different appearance for different day, use FSCalendarDelegateAppearance.
|
||||
*
|
||||
* @see FSCalendarAppearance
|
||||
*/
|
||||
@protocol FSCalendarDelegateAppearance <NSObject>
|
||||
|
||||
@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;
|
||||
- (NSArray *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance eventColorsForDate:(NSDate *)date;
|
||||
- (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance borderDefaultColorForDate:(NSDate *)date;
|
||||
- (UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance borderSelectionColorForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the delegate for a fill color in selected state for the specific date.
|
||||
*/
|
||||
- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance selectionColorForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the delegate for day text color in unselected state for the specific date.
|
||||
*/
|
||||
- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance titleDefaultColorForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the delegate for day text color in selected state for the specific date.
|
||||
*/
|
||||
- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance titleSelectionColorForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the delegate for subtitle text color in unselected state for the specific date.
|
||||
*/
|
||||
- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance subtitleDefaultColorForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the delegate for subtitle text color in selected state for the specific date.
|
||||
*/
|
||||
- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance subtitleSelectionColorForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the delegate for single event color for the specific date.
|
||||
*/
|
||||
- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance eventColorForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the delegate for multiple event colors for the specific date.
|
||||
*/
|
||||
- (nullable NSArray *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance eventColorsForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the delegate for a border color in unselected state for the specific date.
|
||||
*/
|
||||
- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance borderDefaultColorForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the delegate for a border color in selected state for the specific date.
|
||||
*/
|
||||
- (nullable UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance borderSelectionColorForDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Asks the delegate for a shape for the specific date.
|
||||
*/
|
||||
- (FSCalendarCellShape)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance cellShapeForDate:(NSDate *)date;
|
||||
|
||||
|
||||
/**
|
||||
* This function is deprecated
|
||||
*/
|
||||
- (FSCalendarCellStyle)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance cellStyleForDate:(NSDate *)date FSCalendarDeprecated(-calendar:appearance:cellShapeForDate:);
|
||||
|
||||
@end
|
||||
|
|
@ -88,97 +211,379 @@ typedef NS_ENUM(NSUInteger, FSCalendarUnit) {
|
|||
IB_DESIGNABLE
|
||||
@interface FSCalendar : UIView
|
||||
|
||||
/**
|
||||
* The object that acts as the delegate of the calendar.
|
||||
*/
|
||||
@property (weak, nonatomic) IBOutlet id<FSCalendarDelegate> delegate;
|
||||
|
||||
/**
|
||||
* The object that acts as the data source of the calendar.
|
||||
*/
|
||||
@property (weak, nonatomic) IBOutlet id<FSCalendarDataSource> dataSource;
|
||||
|
||||
/**
|
||||
* A special mark will be put on today of the calendar
|
||||
*/
|
||||
@property (strong, nonatomic) NSDate *today;
|
||||
|
||||
/**
|
||||
* The current page of calendar
|
||||
*
|
||||
* @desc In week mode, current page represents the current visible week; In month mode, it means current visible month.
|
||||
*/
|
||||
@property (strong, nonatomic) NSDate *currentPage;
|
||||
|
||||
/**
|
||||
* The locale of month and weekday symbols. Change it to display them in your own language.
|
||||
*
|
||||
* e.g. To display them in Chinese:
|
||||
*
|
||||
* calendar.locale = [NSLocale localeWithLocaleIdentifier:@"zh-CN"];
|
||||
*/
|
||||
@property (strong, nonatomic) NSLocale *locale;
|
||||
|
||||
/**
|
||||
* Represents the NSCalendarIdentifier of calendar. Default is NSCalendarIdentifierGregorian.
|
||||
*
|
||||
* e.g. To display a Persian calendar
|
||||
*
|
||||
* calendar.identifier = NSCalendarIdentifierPersian;
|
||||
*/
|
||||
@property (strong, nonatomic) NSString *identifier;
|
||||
|
||||
/**
|
||||
* The scroll direction of FSCalendar.
|
||||
*
|
||||
* e.g. To make the calendar scroll vertically
|
||||
*
|
||||
* calendar.scrollDirection = FSCalendarScrollDirectionVertical;
|
||||
*/
|
||||
@property (assign, nonatomic) FSCalendarScrollDirection scrollDirection;
|
||||
|
||||
/**
|
||||
* The scope of calendar, change scope will trigger an inner frame change, make sure the frame has been correctly adjusted in
|
||||
*
|
||||
* - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated;
|
||||
*/
|
||||
@property (assign, nonatomic) FSCalendarScope scope;
|
||||
|
||||
/**
|
||||
* The index of the first weekday of the calendar. Give a '2' to make Monday in the first column.
|
||||
*/
|
||||
@property (assign, nonatomic) IBInspectable NSUInteger firstWeekday;
|
||||
|
||||
/**
|
||||
* The height of month header of the calendar. Give a '0' to remove the header.
|
||||
*/
|
||||
@property (assign, nonatomic) IBInspectable CGFloat headerHeight;
|
||||
|
||||
/**
|
||||
* The height of weekday header of the calendar.
|
||||
*/
|
||||
@property (assign, nonatomic) IBInspectable CGFloat weekdayHeight;
|
||||
|
||||
/**
|
||||
* A Boolean value that determines whether users can select a date.
|
||||
*/
|
||||
@property (assign, nonatomic) IBInspectable BOOL allowsSelection;
|
||||
|
||||
/**
|
||||
* A Boolean value that determines whether users can select more than one date.
|
||||
*/
|
||||
@property (assign, nonatomic) IBInspectable BOOL allowsMultipleSelection;
|
||||
|
||||
/**
|
||||
* A Boolean value that determines whether paging is enabled for the calendar.
|
||||
*/
|
||||
@property (assign, nonatomic) IBInspectable BOOL pagingEnabled;
|
||||
|
||||
/**
|
||||
* A Boolean value that determines whether scrolling is enabled for the calendar.
|
||||
*/
|
||||
@property (assign, nonatomic) IBInspectable BOOL scrollEnabled;
|
||||
|
||||
/**
|
||||
* A Boolean value that determines whether scoping animation is centered a visible selected date. Default is YES.
|
||||
*/
|
||||
@property (assign, nonatomic) IBInspectable BOOL focusOnSingleSelectedDate;
|
||||
|
||||
/**
|
||||
* A Boolean value that determines whether the calendar should show days out of month. Default is YES.
|
||||
*/
|
||||
@property (assign, nonatomic) IBInspectable BOOL showsPlaceholders;
|
||||
|
||||
@property (readonly, nonatomic) FSCalendarAppearance *appearance;
|
||||
|
||||
/**
|
||||
* A date object representing the minimum day enable、visible and selectable. (read-only)
|
||||
*/
|
||||
@property (readonly, nonatomic) NSDate *minimumDate;
|
||||
|
||||
/**
|
||||
* A date object representing the maximum day enable、visible and selectable. (read-only)
|
||||
*/
|
||||
@property (readonly, nonatomic) NSDate *maximumDate;
|
||||
|
||||
/**
|
||||
* A date object identifying the section of the selected date. (read-only)
|
||||
*/
|
||||
@property (readonly, nonatomic) NSDate *selectedDate;
|
||||
|
||||
/**
|
||||
* The dates representing the selected dates. (read-only)
|
||||
*/
|
||||
@property (readonly, nonatomic) NSArray *selectedDates;
|
||||
|
||||
/**
|
||||
* Reload the dates and appearance of the calendar.
|
||||
*/
|
||||
- (void)reloadData;
|
||||
- (CGSize)sizeThatFits:(CGSize)size;
|
||||
|
||||
/**
|
||||
* Change the scope of the calendar. Make sure `-calendar:boundingRectWillChange:animated` is correctly adopted.
|
||||
*
|
||||
* @param scope The target scope to change.
|
||||
* @param animated YES if you want to animate the scoping; NO if the change should be immediate.
|
||||
*/
|
||||
- (void)setScope:(FSCalendarScope)scope animated:(BOOL)animated;
|
||||
|
||||
/**
|
||||
* Selects a given date in the calendar.
|
||||
*
|
||||
* @param date A date in the calendar.
|
||||
*/
|
||||
- (void)selectDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Selects a given date in the calendar, optionally scrolling the date to visible area.
|
||||
*
|
||||
* @param date A date in the calendar.
|
||||
* @param scrollToDate A Boolean value that determines whether the calendar should scroll to the selected date to visible area.
|
||||
*/
|
||||
- (void)selectDate:(NSDate *)date scrollToDate:(BOOL)scrollToDate;
|
||||
|
||||
/**
|
||||
* Deselects a given date of the calendar.
|
||||
* @param date A date in the calendar.
|
||||
*/
|
||||
- (void)deselectDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Change the current page of the calendar.
|
||||
*
|
||||
* @param currentPage Representing weekOfYear in week mode, or month in month mode.
|
||||
* @param animated YES if you want to animate the change in position; NO if it should be immediate.
|
||||
*/
|
||||
- (void)setCurrentPage:(NSDate *)currentPage animated:(BOOL)animated;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark - DateTools
|
||||
|
||||
/**
|
||||
* Job for this category:
|
||||
*
|
||||
* 1. Manage date object simplier、faster
|
||||
* 2. Bring date object into a no-timezone system.
|
||||
*
|
||||
* @warning All NSDate instances used in the calendar should be created by:
|
||||
*
|
||||
* - (NSDate *)dateFromString:(NSString *)string format:(NSString *)format;
|
||||
* - (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
|
||||
*
|
||||
*/
|
||||
@interface FSCalendar (DateTools)
|
||||
|
||||
/**
|
||||
* Returns the number of year of the given date
|
||||
*/
|
||||
- (NSInteger)yearOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the number of month of the given date
|
||||
*/
|
||||
- (NSInteger)monthOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the number of day of the given date
|
||||
*/
|
||||
- (NSInteger)dayOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the number of weekday of the given date
|
||||
*/
|
||||
- (NSInteger)weekdayOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the number of weekOfYear of the given date
|
||||
*/
|
||||
- (NSInteger)weekOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the number of hour of the given date
|
||||
*/
|
||||
- (NSInteger)hourOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the number of minite of the given date
|
||||
*/
|
||||
- (NSInteger)miniuteOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the number of seconds of the given date
|
||||
*/
|
||||
- (NSInteger)secondOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the number of rows of the given month
|
||||
*/
|
||||
- (NSInteger)numberOfRowsInMonth:(NSDate *)month;
|
||||
|
||||
/**
|
||||
* Zeronizing hour、minute and second components of the given date
|
||||
*/
|
||||
- (NSDate *)dateByIgnoringTimeComponentsOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the first day of month of the given date
|
||||
*/
|
||||
- (NSDate *)beginingOfMonthOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the last day of month of the given date
|
||||
*/
|
||||
- (NSDate *)endOfMonthOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the first day of week of the given date
|
||||
*/
|
||||
- (NSDate *)beginingOfWeekOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the middle day of week of the given date
|
||||
*/
|
||||
- (NSDate *)middleOfWeekFromDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the next day of the given date
|
||||
*/
|
||||
- (NSDate *)tomorrowOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the previous day of the given date
|
||||
*/
|
||||
- (NSDate *)yesterdayOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the number of days in the month of the given date
|
||||
*/
|
||||
- (NSInteger)numberOfDatesInMonthOfDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Instantiating a date by given string and date format.
|
||||
*
|
||||
* e.g.
|
||||
*
|
||||
* NSDate *date = [calendar dateFromString:@"2000-10-10" format:@"yyyy-MM-dd"];
|
||||
*/
|
||||
- (NSDate *)dateFromString:(NSString *)string format:(NSString *)format;
|
||||
|
||||
/**
|
||||
* Instantiating a date by given numbers of year、month and day.
|
||||
*
|
||||
* e.g.
|
||||
*
|
||||
* NSDate *date = [calendar dateWithYear:2000 month:10 day:10];
|
||||
*/
|
||||
- (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
|
||||
|
||||
/**
|
||||
* Returns a new NSDate object representing the time calculated by adding given number of year to a given date.
|
||||
*/
|
||||
- (NSDate *)dateByAddingYears:(NSInteger)years toDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns a new NSDate object representing the time calculated by substracting given number of year from a given date.
|
||||
*/
|
||||
- (NSDate *)dateBySubstractingYears:(NSInteger)years fromDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns a new NSDate object representing the time calculated by adding given number of month to a given date.
|
||||
*/
|
||||
- (NSDate *)dateByAddingMonths:(NSInteger)months toDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns a new NSDate object representing the time calculated by substracting given number of month from a given date.
|
||||
*/
|
||||
- (NSDate *)dateBySubstractingMonths:(NSInteger)months fromDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns a new NSDate object representing the time calculated by adding given number of week to a given date.
|
||||
*/
|
||||
- (NSDate *)dateByAddingWeeks:(NSInteger)weeks toDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns a new NSDate object representing the time calculated by substracting given number of week from a given date.
|
||||
*/
|
||||
- (NSDate *)dateBySubstractingWeeks:(NSInteger)weeks fromDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns a new NSDate object representing the time calculated by adding given number of day to a given date.
|
||||
*/
|
||||
- (NSDate *)dateByAddingDays:(NSInteger)days toDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns a new NSDate object representing the time calculated by substracting given number of day from a given date.
|
||||
*/
|
||||
- (NSDate *)dateBySubstractingDays:(NSInteger)days fromDate:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns the year-difference between the given dates
|
||||
*/
|
||||
- (NSInteger)yearsFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate;
|
||||
|
||||
/**
|
||||
* Returns the month-difference between the given dates
|
||||
*/
|
||||
- (NSInteger)monthsFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate;
|
||||
|
||||
/**
|
||||
* Returns the day-difference between the given dates
|
||||
*/
|
||||
- (NSInteger)daysFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate;
|
||||
|
||||
/**
|
||||
* Returns the week-difference between the given dates
|
||||
*/
|
||||
- (NSInteger)weeksFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate;
|
||||
|
||||
/**
|
||||
* Returns whether two dates are equal to a given unit of calendar.
|
||||
*/
|
||||
- (BOOL)isDate:(NSDate *)date1 equalToDate:(NSDate *)date2 toCalendarUnit:(FSCalendarUnit)unit;
|
||||
|
||||
/**
|
||||
* Returns whether the given date is in 'today' of the calendar.
|
||||
*/
|
||||
- (BOOL)isDateInToday:(NSDate *)date;
|
||||
|
||||
/**
|
||||
* Returns a string representation of a given date formatted using a specific date format.
|
||||
*/
|
||||
- (NSString *)stringFromDate:(NSDate *)date format:(NSString *)format;
|
||||
|
||||
/**
|
||||
* Returns a string representation of a given date formatted using a yyyy-MM-dd.
|
||||
*/
|
||||
- (NSString *)stringFromDate:(NSDate *)date;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark - Deprecate
|
||||
|
||||
/**
|
||||
* These attributes and functions are deprecated.
|
||||
*/
|
||||
@interface FSCalendar (Deprecated)
|
||||
@property (strong, nonatomic) NSDate *currentMonth FSCalendarDeprecated('currentPage');
|
||||
@property (assign, nonatomic) FSCalendarFlow flow FSCalendarDeprecated('scrollDirection');
|
||||
|
|
@ -189,3 +594,5 @@ IB_DESIGNABLE
|
|||
- (BOOL)date:(NSDate *)date sharesSameDayWithDate:(NSDate *)anotherDate FSCalendarDeprecated(-isDate:equalToDate:toCalendarUnit);
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
@property (readonly, nonatomic) id<FSCalendarDelegateAppearance> delegateAppearance;
|
||||
|
||||
- (void)orientationDidChange:(NSNotification *)notification;
|
||||
- (void)significantTimeDidChange:(NSNotification *)notification;
|
||||
|
||||
- (NSDate *)dateForIndexPath:(NSIndexPath *)indexPath;
|
||||
- (NSDate *)dateForIndexPath:(NSIndexPath *)indexPath scope:(FSCalendarScope)scope;
|
||||
|
|
@ -253,7 +252,7 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
self.animator.collectionViewLayout = self.collectionViewLayout;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(significantTimeDidChange:) name:UIApplicationSignificantTimeChangeNotification object:nil];
|
||||
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
|
|
@ -262,7 +261,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
_collectionView.dataSource = nil;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationSignificantTimeChangeNotification object:nil];
|
||||
}
|
||||
|
||||
#pragma mark - Overriden methods
|
||||
|
|
@ -699,11 +697,6 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
self.orientation = self.currentCalendarOrientation;
|
||||
}
|
||||
|
||||
- (void)significantTimeDidChange:(NSNotification *)notification
|
||||
{
|
||||
self.today = [NSDate date];
|
||||
}
|
||||
|
||||
#pragma mark - Properties
|
||||
|
||||
- (void)setAppearance:(FSCalendarAppearance *)appearance
|
||||
|
|
@ -2223,6 +2216,3 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) {
|
|||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@
|
|||
// Pods
|
||||
//
|
||||
// Created by DingWenchao on 6/29/15.
|
||||
// Copyright © 2016 Wenchao Ding. All rights reserved.
|
||||
//
|
||||
// https://github.com/WenchaoD
|
||||
//
|
||||
|
||||
#import "FSCalendarConstance.h"
|
||||
|
|
@ -34,44 +36,173 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) {
|
|||
FSCalendarCaseOptionsWeekdayUsesSingleUpperCase = 2 << 4,
|
||||
};
|
||||
|
||||
/**
|
||||
* FSCalendarAppearance determines the fonts and colors of components in the calendar.
|
||||
*
|
||||
* @see FSCalendarDelegateAppearance
|
||||
*/
|
||||
@interface FSCalendarAppearance : NSObject
|
||||
|
||||
/**
|
||||
* The font of the day text.
|
||||
*
|
||||
* @warning The size of font is adjusted by calendar size. To turn it off, set adjustsFontSizeToFitContentSize to NO;
|
||||
*/
|
||||
@property (strong, nonatomic) UIFont *titleFont;
|
||||
|
||||
/**
|
||||
* The font of the subtitle text.
|
||||
*
|
||||
* @warning The size of font is adjusted by calendar size. To turn it off, set adjustsFontSizeToFitContentSize to NO;
|
||||
*/
|
||||
@property (strong, nonatomic) UIFont *subtitleFont;
|
||||
|
||||
/**
|
||||
* The font of the weekday text.
|
||||
*
|
||||
* @warning The size of font is adjusted by calendar size. To turn it off, set adjustsFontSizeToFitContentSize to NO;
|
||||
*/
|
||||
@property (strong, nonatomic) UIFont *weekdayFont;
|
||||
|
||||
/**
|
||||
* The font of the month text.
|
||||
*
|
||||
* @warning The size of font is adjusted by calendar size. To turn it off, set adjustsFontSizeToFitContentSize to NO;
|
||||
*/
|
||||
@property (strong, nonatomic) UIFont *headerTitleFont;
|
||||
|
||||
/**
|
||||
* The vertical offset of the day text from default position.
|
||||
*/
|
||||
@property (assign, nonatomic) CGFloat titleVerticalOffset;
|
||||
|
||||
/**
|
||||
* The vertical offset of the suntitle text from default position.
|
||||
*/
|
||||
@property (assign, nonatomic) CGFloat subtitleVerticalOffset;
|
||||
|
||||
/**
|
||||
* The color of event dots.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *eventColor;
|
||||
|
||||
/**
|
||||
* The color of weekday text.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *weekdayTextColor;
|
||||
|
||||
/**
|
||||
* The color of month header text.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *headerTitleColor;
|
||||
|
||||
/**
|
||||
* The date format of the month header.
|
||||
*/
|
||||
@property (strong, nonatomic) NSString *headerDateFormat;
|
||||
|
||||
/**
|
||||
* The alpha value of month label staying on the fringes.
|
||||
*/
|
||||
@property (assign, nonatomic) CGFloat headerMinimumDissolvedAlpha;
|
||||
|
||||
/**
|
||||
* The day text color for unselected state.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *titleDefaultColor;
|
||||
|
||||
/**
|
||||
* The day text color for selected state.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *titleSelectionColor;
|
||||
|
||||
/**
|
||||
* The day text color for today in the calendar.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *titleTodayColor;
|
||||
|
||||
/**
|
||||
* The day text color for days out of current month.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *titlePlaceholderColor;
|
||||
|
||||
/**
|
||||
* The day text color for weekend.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *titleWeekendColor;
|
||||
|
||||
/**
|
||||
* The subtitle text color for unselected state.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *subtitleDefaultColor;
|
||||
|
||||
/**
|
||||
* The subtitle text color for selected state.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *subtitleSelectionColor;
|
||||
|
||||
/**
|
||||
* The subtitle text color for today in the calendar.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *subtitleTodayColor;
|
||||
|
||||
/**
|
||||
* The subtitle text color for days out of current month.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *subtitlePlaceholderColor;
|
||||
|
||||
/**
|
||||
* The subtitle text color for weekend.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *subtitleWeekendColor;
|
||||
|
||||
/**
|
||||
* The fill color of the shape for selected state.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *selectionColor;
|
||||
|
||||
/**
|
||||
* The fill color of the shape for today.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *todayColor;
|
||||
|
||||
/**
|
||||
* The fill color of the shape for today and selected state.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *todaySelectionColor;
|
||||
|
||||
/**
|
||||
* The border color of the shape for unselected state.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *borderDefaultColor;
|
||||
|
||||
/**
|
||||
* The border color of the shape for selected state.
|
||||
*/
|
||||
@property (strong, nonatomic) UIColor *borderSelectionColor;
|
||||
|
||||
/**
|
||||
* The shape appears when a day is selected or today.
|
||||
*
|
||||
* @see FSCalendarCellShape
|
||||
*/
|
||||
@property (assign, nonatomic) FSCalendarCellShape cellShape;
|
||||
|
||||
/**
|
||||
* The case options manage the case of month label and weekday symbols.
|
||||
*
|
||||
* @see FSCalendarCaseOptions
|
||||
*/
|
||||
@property (assign, nonatomic) FSCalendarCaseOptions caseOptions;
|
||||
|
||||
/**
|
||||
* A Boolean value indicates whether the calendar should adjust font size by its content size.
|
||||
*
|
||||
* @see titleFont
|
||||
* @see subtitleFont
|
||||
* @see weekdayFont
|
||||
* @see headerTitleFont
|
||||
*/
|
||||
@property (assign, nonatomic) BOOL adjustsFontSizeToFitContentSize;
|
||||
|
||||
#if TARGET_INTERFACE_BUILDER
|
||||
|
|
@ -82,10 +213,16 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) {
|
|||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Triggers an appearance update.
|
||||
*/
|
||||
- (void)invalidateAppearance;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* These functions and attributes are deprecated.
|
||||
*/
|
||||
@interface FSCalendarAppearance (Deprecated)
|
||||
|
||||
@property (assign, nonatomic) FSCalendarCellStyle cellStyle FSCalendarDeprecated('cellShape');
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@
|
|||
// Pods
|
||||
//
|
||||
// Created by DingWenchao on 6/29/15.
|
||||
// Copyright © 2016 Wenchao Ding. All rights reserved.
|
||||
//
|
||||
// https://github.com/WenchaoD
|
||||
//
|
||||
|
||||
#import "FSCalendarAppearance.h"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@
|
|||
// FSCalendar
|
||||
//
|
||||
// Created by dingwenchao on 8/28/15.
|
||||
// Copyright (c) 2015 wenchaoios. All rights reserved.
|
||||
// Copyright © 2016 Wenchao Ding. All rights reserved.
|
||||
//
|
||||
// https://github.com/WenchaoD
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@
|
|||
// FSCalendar
|
||||
//
|
||||
// Created by dingwenchao on 8/28/15.
|
||||
// Copyright (c) 2015 wenchaoios. All rights reserved.
|
||||
// Copyright © 2016 Wenchao Ding. All rights reserved.
|
||||
//
|
||||
// https://github.com/WenchaoD
|
||||
//
|
||||
|
||||
#import "FSCalendarConstance.h"
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.0.0</string>
|
||||
<string>2.0.1</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@
|
|||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/**
|
||||
* This category is deprecated in this framework as it premised that the calendar should be gregorian. But feel free to use it for gregorian-only.
|
||||
*/
|
||||
@interface NSDate (FSExtension)
|
||||
|
||||
@property (readonly, nonatomic) NSInteger fs_year;
|
||||
|
|
|
|||
|
|
@ -23,45 +23,45 @@ class ViewController: UIViewController, FSCalendarDataSource, FSCalendarDelegate
|
|||
// calendar.allowsMultipleSelection = true
|
||||
|
||||
// Uncomment this to test month->week and week->month transition
|
||||
/*
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (Int64)(2.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { () -> Void in
|
||||
self.calendar.setScope(.Week, animated: true)
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (Int64)(1.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { () -> Void in
|
||||
self.calendar.setScope(.Month, animated: true)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
func minimumDateForCalendar(calendar: FSCalendar!) -> NSDate! {
|
||||
func minimumDateForCalendar(calendar: FSCalendar) -> NSDate {
|
||||
return calendar.dateWithYear(2015, month: 1, day: 1)
|
||||
}
|
||||
|
||||
func maximumDateForCalendar(calendar: FSCalendar!) -> NSDate! {
|
||||
func maximumDateForCalendar(calendar: FSCalendar) -> NSDate {
|
||||
return calendar.dateWithYear(2016, month: 10, day: 31)
|
||||
}
|
||||
|
||||
func calendar(calendar: FSCalendar!, numberOfEventsForDate date: NSDate!) -> Int {
|
||||
func calendar(calendar: FSCalendar, numberOfEventsForDate date: NSDate) -> Int {
|
||||
let day = calendar.dayOfDate(date)
|
||||
return day % 5 == 0 ? day/5 : 0;
|
||||
}
|
||||
|
||||
func calendarCurrentPageDidChange(calendar: FSCalendar!) {
|
||||
func calendarCurrentPageDidChange(calendar: FSCalendar) {
|
||||
NSLog("change page to \(calendar.stringFromDate(calendar.currentPage))")
|
||||
}
|
||||
|
||||
func calendar(calendar: FSCalendar!, didSelectDate date: NSDate!) {
|
||||
func calendar(calendar: FSCalendar, didSelectDate date: NSDate) {
|
||||
NSLog("calendar did select date \(calendar.stringFromDate(date))")
|
||||
}
|
||||
|
||||
func calendarCurrentScopeWillChange(calendar: FSCalendar!, animated: Bool) {
|
||||
calendarHeightConstraint.constant = calendar.sizeThatFits(CGSizeZero).height
|
||||
func calendar(calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
|
||||
calendarHeightConstraint.constant = bounds.height
|
||||
view.layoutIfNeeded()
|
||||
}
|
||||
|
||||
func calendar(calendar: FSCalendar!, imageForDate date: NSDate!) -> UIImage! {
|
||||
func calendar(calendar: FSCalendar, imageForDate date: NSDate) -> UIImage? {
|
||||
return [13,24].containsObject(calendar.dayOfDate(date)) ? UIImage(named: "icon_cat") : nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue