Install FSCalendar manually
masterFSCalendar folder directly into your Xcode project.repository·master·Indexed 27 days ago
https://github.com/wenchaod/fscalendarA highly customizable calendar component for iOS supporting Objective-C and Swift. Features include interactive gestures, DIY cell customization, support for Today Extensions, multiple date selection, and flexible scroll directions. The library can be installed via CocoaPods, Carthage, Swift Package Manager (SPM), or manual integration.
FSCalendar folder directly into your Xcode project.UIView object onto your ViewController Scene.Custom Class to FSCalendar.dataSource and delegate outlets to your ViewController.FSCalendarDataSource and FSCalendarDelegate protocols in your ViewController.To install FSCalendar using Carthage (for iOS 8+), add the following to your Cartfile:
github "WenchaoD/FSCalendar"FSCalendar does not update its frame automatically. You must implement the boundingRectWillChange:animated: delegate method to update your layout when the calendar's bounds change.
// For AutoLayout
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
self.calendarHeightConstraint.constant = CGRectGetHeight(bounds);
[self.view layoutIfNeeded];
}
// For Manual Layout
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
calendar.frame = (CGRect){calendar.frame.origin,bounds.size};
}
// For Masonry
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
[calendar mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@(bounds.size.height));
}];
[self.view layoutIfNeeded];
}
// For SnapKit (Swift)
func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
calendar.snp.updateConstraints { (make) in
make.height.equalTo(bounds.height)
}
self.view.layoutIfNeeded()
}Add the following dependency to your Swift Package:
.package(url: "https://github.com/WenchaoD/FSCalendar.git", from: "2.8.4")showsPlaceholders is false), the calendar's bounds may change. You must adjust the frame or constraints in the boundingRectWillChange delegate method to ensure the layout remains correct.To install FSCalendar using CocoaPods, add the following to your Podfile. Note that for iOS 7 compatibility, NSCalendarExtension is required.
# For iOS8+
use_frameworks!
target '<Your Target Name>' do
pod 'FSCalendar'
end
# For iOS7+
target '<Your Target Name>' do
pod 'FSCalendar'
endYou can initialize and add the calendar to your view hierarchy programmatically in Objective-C.
@property (weak , nonatomic) FSCalendar *calendar;
// 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;To use FSCalendar in Swift, you must first create a Bridging Header. Note that in Swift 3+, NSDate and NSDateFormatter are renamed to Date and DateFormatter.
fileprivate weak var calendar: FSCalendar!
// 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 = calendarFSCalendarDataSource to display extra information for specific dates.The delegate method calendarCurrentMonthDidChange is called whenever the user changes the month or the week.
func calendarCurrentMonthDidChange(_ calendar: FSCalendar!) {
// Do something
}