Drag all files under FSCalendar folder into your project. 👍
Alternatively to give it a test run, simply press command+u in Example-Objc or Example-Swift and launch the UITest Target.
Only the methods marked “👍” support IBInspectable / IBDesignable feature. Have fun with Interface builder
Setup
Use Interface Builder
1、 Drag an UIView object to ViewController Scene
2、 Change the Custom Class to FSCalendar
3、 Link dataSource and delegate to the ViewController
4、 Finally, implement FSCalendarDataSource and FSCalendarDelegate in your ViewController
// 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
To use FSCalendar in Swift3, see Example-Swift for details.
Warning
FSCalendardoesn’t update frame by itself, Please implement
For AutoLayout
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
self.calendarHeightConstraint.constant = CGRectGetHeight(bounds);
// Do other updates here
[self.view layoutIfNeeded];
}
For Manual Layout
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
calendar.frame = (CGRect){calendar.frame.origin,bounds.size};
// Do other updates here
}
If you are using Masonry
- (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];
}
If you are using SnapKit
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()
}
Roll with Interface Builder
Pre-knowledge
In Swift3, NSDate and NSDateFormatter have been renamed to Date and DateFormatter , see Example-Swift for details.
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
Table of contents
Screenshots
iPhone
iPad
Safe Orientation
Today Extension
Interactive Scope Gesture
DIY support
Swipe-To-Choose
Swipe-To-Choose
Swipe-To-Choose
Swipe-To-Choose
Achievement of Users
More Achievements are available in FSCalendar Gallery
Installation
CocoaPods:
Carthage:
SPM:
Add dependency:
Manually:
FSCalendar
folder into your project. 👍Setup
Use Interface Builder
1、 Drag an UIView object to ViewController Scene 2、 Change the
Custom Class
toFSCalendar
3、 Link
dataSource
anddelegate
to the ViewController4、 Finally, implement
FSCalendarDataSource
andFSCalendarDelegate
in yourViewController
Or use code
Or swift
FSCalendar
in swift, you need to Create Bridge Header first.Warning
FSCalendar
doesn’t update frame by itself, Please implementRoll with Interface Builder
Pre-knowledge
How to create NSDate object
Then:
Then:
How to print out NSDate object
How to manipulate NSDate with NSCalendar
Support this repo
Contact
License
FSCalendar is available under the MIT license. See the LICENSE file for more info.
Documentation | More Usage | 简书