### Install FSCalendar with Carthage for iOS 8+ Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Integrates FSCalendar into your project using Carthage, suitable for iOS 8 and above. ```Ruby github "WenchaoD/FSCalendar" ``` -------------------------------- ### Handling Date Selection in FSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md Demonstrates how to implement the `FSCalendarDelegate` method `didSelectDate` to perform actions when a date is selected. ```Objective-C // FSCalendarDelegate - (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date { // Do something } ``` ```Swift // FSCalendarDelegate func calendar(calendar: FSCalendar!, didSelectDate date: NSDate!) { } ``` -------------------------------- ### Set First Day of Week in FSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md This snippet shows how to configure FSCalendar to start the week on a specific day, such as Monday. The `firstWeekday` property accepts an integer where 1 represents Sunday, 2 represents Monday, and so on. ```objective-c _calendar.firstWeekday = 2; ``` ```swift calendar.firstWeekday = 2 ``` -------------------------------- ### Receiving Month/Week Change Notifications in FSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md Illustrates how to implement the `calendarCurrentMonthDidChange` delegate method to get notified when the calendar's displayed month or week changes. ```Objective-C - (void)calendarCurrentMonthDidChange:(FSCalendar *)calendar { // Do something } ``` ```Swift func calendarCurrentMonthDidChange(_ calendar: FSCalendar!) { // Do something } ``` -------------------------------- ### Setting Minimum and Maximum Dates in FSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md Explains how to define the selectable date range using `minimumDateForCalendar` and `maximumDateForCalendar` from `FSCalendarDataSource`. ```Objective-C // FSCalendarDataSource - (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar { return yourMinimumDate; } - (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar { return yourMaximumDate; } ``` -------------------------------- ### Displaying Images for Specific Dates in FSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md Shows how to use the `FSCalendarDataSource` method `imageForDate` to display a custom image on a calendar date. ```Objective-C // FSCalendarDataSource - (UIImage *)calendar:(FSCalendar *)calendar imageForDate:(NSDate *)date { return anyImage; } ``` ```Swift // FSCalendarDataSource func calendar(_ calendar: FSCalendar!, imageFor date: NSDate!) -> UIImage! { return anyImage } ``` -------------------------------- ### Install FSCalendar with CocoaPods for iOS 7+ Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Adds FSCalendar to your project using CocoaPods, requiring NSCalendarExtension for iOS 7 compatibility. ```Ruby target '' do pod 'FSCalendar' end ``` -------------------------------- ### Hiding Top and Bottom Borders in FSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md Illustrates how to hide the top and bottom borders of the FSCalendar by setting the `clipsToBounds` property. ```Objective-C calendar.clipsToBounds = YES ``` ```Swift calendar.clipsToBounds = true ``` -------------------------------- ### Displaying Event Dots in FSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md Demonstrates how to implement the `FSCalendarDataSource` method `hasEventForDate` to display an event dot for specific dates on the calendar. ```Objective-C // FSCalendarDataSource - (BOOL)calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date { return shouldShowEventDot; } ``` ```Swift // FSCalendarDataSource func calendar(calendar: FSCalendar!, hasEventForDate date: NSDate!) -> Bool { return shouldShowEventDot } ``` -------------------------------- ### Reloading FSCalendar Data Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md Demonstrates how to refresh the calendar's display, similar to `reloadData` in `UITableView` or `UICollectionView`, after data changes. ```Objective-C [self.calendar reloadData]; ``` -------------------------------- ### Install FSCalendar with CocoaPods for iOS 8+ Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Adds FSCalendar to your project using CocoaPods, enabling framework support for iOS 8 and later. ```Ruby use_frameworks! target '' do pod 'FSCalendar' end ``` -------------------------------- ### Adjusting Header Dissolved Alpha in FSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md Explains how to hide the header's dissolved alpha effect by setting `headerMinimumDissolvedAlpha` to 0.0. ```Objective-C self.calendar.appearance.headerMinimumDissolvedAlpha = 0.0; ``` -------------------------------- ### Hiding the Today Circle in FSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md Provides a solution to hide the 'today' circle indicator on the calendar by setting the `today` property to nil. ```Objective-C self.calendar.today = nil; ``` -------------------------------- ### Preventing Date Selection in FSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md Shows how to use the `FSCalendarDelegate` method `shouldSelectDate` to conditionally prevent a date from being selected. ```Objective-C // FSCalendarDelegate - (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date { if ([dateShouldNotBeSelected]) { return NO; } return YES; } ``` ```Swift func calendar(calendar: FSCalendar!, shouldSelectDate date: NSDate!) -> Bool { if dateShouldNotBeSelected { return false } return true } ``` -------------------------------- ### Enable Multiple Date Selection in FSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md This snippet demonstrates how to allow users to select multiple dates simultaneously in FSCalendar. By default, only a single date can be selected at a time, so this property must be set to enable multi-selection. ```objective-c calendar.allowsMultipleSelection = YES; ``` ```swift calendar.allowsMultipleSelection = true; ``` -------------------------------- ### Calculate Next Day's Date with NSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Demonstrates how to get an NSDate object for the next day from a specified date. The dateByAddingUnit:value:toDate:options: method is used to add one NSCalendarUnitDay to the original date. ```Objective-C NSDate *nextDay = [self.gregorain dateByAddingUnit:NSCalendarUnitDay value:1 toDate:date options:0]; ``` -------------------------------- ### Customize FSCalendar Header Date Format Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md This snippet demonstrates how to change the date format displayed in the FSCalendar header. The `headerDateFormat` property of the `appearance` object accepts a standard date format string, allowing for flexible display options. ```objective-c calendar.appearance.headerDateFormat = @"MMM yy"; ``` ```swift calendar.appearance.headerDateFormat = "MMM yy" ``` -------------------------------- ### Customize FSCalendar Appearance Colors Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md This snippet illustrates how to customize various color properties of FSCalendar's appearance. Properties like `weekdayTextColor`, `headerTitleColor`, `eventColor`, `selectionColor`, `todayColor`, and `todaySelectionColor` can be set to match your application's theme, offering extensive visual customization. ```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]; ``` ```swift 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 ``` -------------------------------- ### Adjust FSCalendar Frame with Manual Layout (Objective-C) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Implements the `calendar:boundingRectWillChange:animated:` delegate method to dynamically update the calendar's frame when its bounding rectangle changes, specifically for manual layout setups. ```Objective-C - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated { calendar.frame = (CGRect){calendar.frame.origin,bounds.size}; // Do other updates here } ``` -------------------------------- ### Display Subtitles for Dates in FSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md This snippet demonstrates how to add a subtitle below each date in FSCalendar by implementing the `calendar:subtitleForDate:` delegate method from `FSCalendarDataSource`. This allows for displaying additional information or custom text for specific dates within the calendar view. ```objective-c // FSCalendarDataSource - (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date { return yourSubtitle; } ``` ```swift // FSCalendarDataSource func calendar(_ calendar: FSCalendar!, subtitleFor date: NSDate!) -> String! { return yourSubtitle } ``` -------------------------------- ### Adjust FSCalendar Frame with AutoLayout (Objective-C) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Implements the `calendar:boundingRectWillChange:animated:` delegate method to dynamically update the calendar's height constraint when its bounding rectangle changes, specifically for AutoLayout setups. ```Objective-C - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated { self.calendarHeightConstraint.constant = CGRectGetHeight(bounds); // Do other updates here [self.view layoutIfNeeded]; } ``` -------------------------------- ### Set FSCalendar Scope to Month Mode Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md This snippet shows how to explicitly set FSCalendar to display in month mode. This is the default scope, but can be set to revert to month view after changing to week mode or for clarity. ```objective-c _calendar.scope = FSCalendarScopeMonth; // By default ``` ```swift calendar.scope = .month ``` -------------------------------- ### Configure FSCalendar for Horizontal Scrolling Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md This snippet shows how to explicitly set the scroll direction of FSCalendar to horizontal. This is the default behavior, but can be set for clarity or to revert a previous change in scroll direction. ```objective-c _calendar.scrollDirection = FSCalendarScrollDirectionHorizontal; // By default ``` ```swift calendar.scrollDirection = .Horizontal ``` -------------------------------- ### Check Date Relative to Today, Yesterday, Tomorrow, or Weekend Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Provides examples of using NSCalendar methods to determine if a given NSDate falls on today, yesterday, tomorrow, or a weekend. These boolean checks simplify common date comparisons. ```Objective-C BOOL isToday = [self.gregorian isDateInToday:date]; BOOL isYesterday = [self.gregorian isDateInYesterday:date]; BOOL isTomorrow = [self.gregorian isDateInTomorrow:date]; BOOL isWeekend = [self.gregorian isDateInWeekend:date]; ``` -------------------------------- ### Set FSCalendar Scope to Week Mode Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md This snippet demonstrates how to configure FSCalendar to display in week mode, showing only one week at a time. This changes the calendar's visual scope from the default month view to a more focused weekly view. ```objective-c _calendar.scope = FSCalendarScopeWeek; ``` ```swift calendar.scope = .week ``` -------------------------------- ### Configure FSCalendar for Vertical Scrolling Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md This snippet demonstrates how to set the scroll direction of FSCalendar to vertical. This changes the orientation of month or week navigation, allowing users to scroll through dates vertically. By default, FSCalendar scrolls horizontally. ```objective-c _calendar.scrollDirection = FSCalendarScrollDirectionVertical; ``` ```swift calendar.scrollDirection = .vertical ``` -------------------------------- ### Adjust FSCalendar Frame on Bounds Change Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md When FSCalendar's scope changes (e.g., from month to week mode) or placeholders are hidden, its bounding rectangle may change. This delegate method, `calendar:boundingRectWillChange:animated:`, should be implemented to adjust the calendar's frame or update AutoLayout constraints accordingly, ensuring proper layout. ```objc // For autoLayout - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated { _calendarHeightConstraint.constant = CGRectGetHeight(bounds); [self.view layoutIfNeeded]; } ``` ```objc // For manual layout - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated { calendar.frame = (CGRect){calendar.frame.origin,bounds.size}; } ``` -------------------------------- ### Customize FSCalendar Day Shape Border Radius Source: https://github.com/wenchaod/fscalendar/blob/master/MOREUSAGE.md This snippet shows how to change the shape of the day cells in FSCalendar by adjusting their border radius. Setting `borderRadius` to 0 will make the day cells rectangular instead of the default circular shape, providing a different visual style. ```objective-c calendar.appearance.borderRadius = 0 ``` ```swift calendar.appearance.borderRadius = 0 ``` -------------------------------- ### Initialize and Configure FSCalendar (Swift) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Initializes an FSCalendar instance with a specified frame, sets its data source and delegate, and adds it as a subview to the current view controller's view. This is typically done in `loadView` or `viewDidLoad`. ```Swift // In loadView or viewDidLoad let calendar = FSCalendar(frame: CGRect(x: 0, y: 0, width: 320, height: 300)) calendar.dataSource = self calendar.delegate = self view.addSubview(calendar) self.calendar = calendar ``` -------------------------------- ### Initialize and Configure FSCalendar (Objective-C) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Initializes an FSCalendar instance with a specified frame, sets its data source and delegate, and adds it as a subview to the current view controller's view. This is typically done in `loadView` or `viewDidLoad`. ```Objective-C // In loadView(Recommended) or viewDidLoad FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 0, 320, 300)]; calendar.dataSource = self; calendar.delegate = self; [self.view addSubview:calendar]; self.calendar = calendar; ``` -------------------------------- ### Initialize Gregorian NSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Demonstrates how to initialize an instance of NSCalendar with the Gregorian calendar identifier. This calendar object is then used for various date and time manipulations. ```Objective-C self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian]; ``` -------------------------------- ### Initialize NSDateFormatter for Printing (Objective-C) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Initializes an NSDateFormatter instance and sets its date format to 'yyyy/MM/dd' for converting NSDate objects into formatted strings for display. ```Objective-C self.formatter = [[NSDateFormatter alloc] init]; self.formatter.dateFormat = @"yyyy/MM/dd"; ``` -------------------------------- ### Generate Specific NSDate with NSCalendar (Objective-C) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Creates a specific NSDate object for a given year, month, and day using a pre-configured NSCalendar instance. This method allows precise date construction. ```Objective-C NSDate *date = [gregorian dateWithEra:1 year:2016 month:9 day:10 hour:0 minute:0 second:0 nanosecond:0]; // 2016-09-10 00:00:00 ``` -------------------------------- ### Calculate Next Month's Date with NSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Shows how to obtain an NSDate object representing the next month from a given date. This is achieved by adding one NSCalendarUnitMonth to the original date using dateByAddingUnit:value:toDate:options:. ```Objective-C NSDate *nextMonth = [self.gregorain dateByAddingUnit:NSCalendarUnitMonth value:1 toDate:date options:0]; ``` -------------------------------- ### Create NSCalendar Object (Objective-C) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Initializes an NSCalendar instance with the Gregorian identifier, which is essential for creating and manipulating NSDate objects based on a specific calendar system. ```Objective-C self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian]; ``` -------------------------------- ### Adjust FSCalendar Frame with Masonry (Objective-C) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Implements the `calendar:boundingRectWillChange:animated:` delegate method to dynamically update the calendar's height constraint using Masonry when its bounding rectangle changes. ```Objective-C - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated { [calendar mas_updateConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@(bounds.size.height)); // Do other updates }]; [self.view layoutIfNeeded]; } ``` -------------------------------- ### Print NSDate Object to String (Objective-C) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Converts an NSDate object into a formatted string using a pre-configured NSDateFormatter and logs the result to the console. ```Objective-C NSString *string = [self.formatter stringFromDate:date]; NSLog(@"Date is %@", string); ``` -------------------------------- ### Add FSCalendar dependency with Swift Package Manager Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Adds FSCalendar as a package dependency to your Swift project using Swift Package Manager. ```Swift .package(url: "https://github.com/WenchaoD/FSCalendar.git", from: "2.8.4") ``` -------------------------------- ### Adjust FSCalendar Frame with SnapKit (Swift) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Implements the `calendar(_:boundingRectWillChange:animated:)` delegate method to dynamically update the calendar's height constraint using SnapKit when its bounding rectangle changes. ```Swift func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) { calendar.snp.updateConstraints { (make) in make.height.equalTo(bounds.height) // Do other updates } self.view.layoutIfNeeded() } ``` -------------------------------- ### Initialize NSDateFormatter for Parsing (Objective-C) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Initializes an NSDateFormatter instance and sets its date format to 'yyyy-MM-dd' for parsing date strings into NSDate objects. ```Objective-C self.formatter = [[NSDateFormatter alloc] init]; self.formatter.dateFormat = @"yyyy-MM-dd"; ``` -------------------------------- ### Extract Date Components from NSDate using NSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Illustrates how to retrieve individual date and time components (era, year, month, day, hour, minute) from an NSDate object using an NSCalendar instance. This allows for granular access to date information. ```Objective-C NSInteger era = [self.gregorian component:NSCalendarUnitEra fromDate:date]; NSInteger year = [self.gregorian component:NSCalendarUnitYear fromDate:date]; NSInteger month = [self.gregorian component:NSCalendarUnitMonth fromDate:date]; NSInteger day = [self.gregorian component:NSCalendarUnitDay fromDate:date]; NSInteger hour = [self.gregorian component:NSCalendarUnitHour fromDate:date]; NSInteger minute = [self.gregorian component:NSCalendarUnitMinute fromDate:date]; ... ``` -------------------------------- ### Compare Two NSDate Objects with NSCalendar Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Illustrates various ways to compare two NSDate objects using NSCalendar. This includes checking if two dates fall on the same day, comparing dates up to a specific granularity (e.g., year, month), and checking for equality at a given unit granularity. ```Objective-C BOOL sameDay = [self.gregorian isDate:date1 inSameDayAsDate:date2]; // Yes if the date1 and date2 are in same day [self.gregorian compareDate:date1 toDate:date2 toUnitGranularity:unit]; // compare the era/year/month/day/hour/minute .etc ... // return NSOrderAscending/NSOrderSame/NSOrderDecending BOOL inSameUnit = [self.gregorian isDate:date1 equalToDate:date2 toUnitGranularity:unit]; // if the given unit (era/year/month/day/hour/minute .etc) are the same ``` -------------------------------- ### Create NSDate Object from String (Objective-C) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Parses a date string (e.g., '2016-09-10') into an NSDate object using a pre-configured NSDateFormatter. This is useful for converting user input or data from external sources. ```Objective-C NSDate *date = [self.formatter dateFromString:@"2016-09-10"]; ``` -------------------------------- ### Declare FSCalendar Property (Swift) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Declares a fileprivate weak property for FSCalendar in Swift to hold a reference to the calendar instance. Requires a bridging header for Objective-C interoperability. ```Swift fileprivate weak var calendar: FSCalendar! ``` -------------------------------- ### Declare FSCalendar Property (Objective-C) Source: https://github.com/wenchaod/fscalendar/blob/master/README.md Declares a weak, nonatomic property for FSCalendar in Objective-C to hold a reference to the calendar instance. ```Objective-C @property (weak , nonatomic) FSCalendar *calendar; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.