|
| 1 | +FSCalendar - Xamarin iOS Binding Library |
| 2 | +===== |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +# Table of contents |
| 7 | +* [Screenshots](#screenshots) |
| 8 | +* [Installation](#installation) |
| 9 | +* [Pre-knowledge](#pre-knowledge) |
| 10 | + |
| 11 | +## <a id="screenshots"></a>Screenshots |
| 12 | + |
| 13 | +### iPhone |
| 14 | + |
| 15 | + |
| 16 | +### iPad |
| 17 | + |
| 18 | + |
| 19 | +### Safe Orientation |
| 20 | + |
| 21 | + |
| 22 | +### Today Extension |
| 23 | +| iOS8/9 | iOS10 | |
| 24 | +|--------------|-------------| |
| 25 | +||| |
| 26 | + |
| 27 | +### Interactive Scope Gesture |
| 28 | +|  | |
| 29 | +| ---- | |
| 30 | + |
| 31 | +### DIY support |
| 32 | +|  | |
| 33 | +| ------------- | |
| 34 | +> To customize your own cell, view DIY Example in `Example-Swift` or `Example-Objc` |
| 35 | +
|
| 36 | + |
| 37 | +### Swipe-To-Choose |
| 38 | + |
| 39 | +|Single-Selection<br/>Swipe-To-Choose|Multiple-Selection<br/>Swipe-To-Choose|DIY<br/>Swipe-To-Choose| |
| 40 | +|----------|--------|--------| |
| 41 | +|||| |
| 42 | + |
| 43 | +## Achievement of Users <a id="achievement"></a> |
| 44 | + |
| 45 | +|  |  |  |  | |
| 46 | +| ------------- | ------------- | ------------- | ------------- | |
| 47 | + |
| 48 | +#### [***More Achievements***](https://github.com/WenchaoD/FSCalendar/wiki/) are available in [***FSCalendar Gallery***](https://github.com/WenchaoD/FSCalendar/wiki/) |
| 49 | + |
| 50 | +=== |
| 51 | + |
| 52 | +# <a id="installation"></a>Installation |
| 53 | +``` |
| 54 | + Install-Package Naxam.FSCalendar.iOS |
| 55 | +``` |
| 56 | + |
| 57 | +# Setup |
| 58 | + |
| 59 | +## Use Interface Builder |
| 60 | + |
| 61 | +1、 Drag an UIView object to ViewController Scene |
| 62 | +2、 Change the `Custom Class` to `FSCalendar`<br/> |
| 63 | +3、 Link `dataSource` and `delegate` to the ViewController <br/> |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +4、 Finally, implement `FSCalendarDataSource` and `FSCalendarDelegate` in your `ViewController` |
| 68 | + |
| 69 | +## Or use code |
| 70 | + |
| 71 | +```objc |
| 72 | +@property (weak , nonatomic) FSCalendar *calendar; |
| 73 | +``` |
| 74 | +```objc |
| 75 | +// In loadView(Recommended) or viewDidLoad |
| 76 | +FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 0, 320, 300)]; |
| 77 | +calendar.dataSource = self; |
| 78 | +calendar.delegate = self; |
| 79 | +[self.view addSubview:calendar]; |
| 80 | +self.calendar = calendar; |
| 81 | +``` |
| 82 | +
|
| 83 | +* For ***AutoLayout*** |
| 84 | +
|
| 85 | +```objc |
| 86 | +- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated |
| 87 | +{ |
| 88 | + self.calendarHeightConstraint.constant = CGRectGetHeight(bounds); |
| 89 | + // Do other updates here |
| 90 | + [self.view layoutIfNeeded]; |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +* For ***Manual Layout*** |
| 95 | + |
| 96 | +```objc |
| 97 | +- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated |
| 98 | +{ |
| 99 | + calendar.frame = (CGRect){calendar.frame.origin,bounds.size}; |
| 100 | + // Do other updates here |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +* If you are using ***Masonry*** |
| 105 | + |
| 106 | +```objc |
| 107 | +- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated |
| 108 | +{ |
| 109 | + [calendar mas_updateConstraints:^(MASConstraintMaker *make) { |
| 110 | + make.height.equalTo(@(bounds.size.height)); |
| 111 | + // Do other updates |
| 112 | + }]; |
| 113 | + [self.view layoutIfNeeded]; |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +### <a id="roll_with_interface_builder"></a> Roll with Interface Builder |
| 118 | + |
| 119 | + |
| 120 | +# <a id="pre-knowledge"></a>Pre-knowledge |
| 121 | + |
| 122 | +## How to create NSDate object |
| 123 | + |
| 124 | +* By **NSCalendar**. |
| 125 | + |
| 126 | +```objc |
| 127 | +self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian]; |
| 128 | +``` |
| 129 | +
|
| 130 | +Then: |
| 131 | +
|
| 132 | +```objc |
| 133 | +NSDate *date = [gregorian dateWithEra:1 year:2016 month:9 day:10 hour:0 minute:0 second:0 nanosecond:0]; |
| 134 | +// 2016-09-10 00:00:00 |
| 135 | +``` |
| 136 | + |
| 137 | + |
| 138 | +* Or by **NSDateFormatter** |
| 139 | + |
| 140 | +```objc |
| 141 | +self.formatter = [[NSDateFormatter alloc] init]; |
| 142 | +self.formatter.dateFormat = @"yyyy-MM-dd"; |
| 143 | +``` |
| 144 | + |
| 145 | +Then: |
| 146 | + |
| 147 | +```objc |
| 148 | +NSDate *date = [self.formatter dateFromString:@"2016-09-10"]; |
| 149 | +``` |
| 150 | +
|
| 151 | +## How to print out NSDate object |
| 152 | +
|
| 153 | +* Use **NSDateFormatter** |
| 154 | +
|
| 155 | +```objc |
| 156 | +self.formatter = [[NSDateFormatter alloc] init]; |
| 157 | +self.formatter.dateFormat = @"yyyy/MM/dd"; |
| 158 | +``` |
| 159 | + |
| 160 | +```objc |
| 161 | +NSString *string = [self.formatter stringFromDate:date]; |
| 162 | +NSLog(@"Date is %@", string); |
| 163 | +``` |
| 164 | +
|
| 165 | +## How to manipulate NSDate with NSCalendar |
| 166 | +
|
| 167 | +```objc |
| 168 | +self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian]; |
| 169 | +``` |
| 170 | +* Get component of NSDate |
| 171 | + |
| 172 | +```objc |
| 173 | +NSInteger era = [self.gregorian component:NSCalendarUnitEra fromDate:date]; |
| 174 | +NSInteger year = [self.gregorian component:NSCalendarUnitYear fromDate:date]; |
| 175 | +NSInteger month = [self.gregorian component:NSCalendarUnitMonth fromDate:date]; |
| 176 | +NSInteger day = [self.gregorian component:NSCalendarUnitDay fromDate:date]; |
| 177 | +NSInteger hour = [self.gregorian component:NSCalendarUnitHour fromDate:date]; |
| 178 | +NSInteger minute = [self.gregorian component:NSCalendarUnitMinute fromDate:date]; |
| 179 | +... |
| 180 | + |
| 181 | +``` |
| 182 | +
|
| 183 | +* Get next **month** |
| 184 | +
|
| 185 | +```objc |
| 186 | +NSDate *nextMonth = [self.gregorain dateByAddingUnit:NSCalendarUnitMonth value:1 toDate:date options:0]; |
| 187 | +``` |
| 188 | + |
| 189 | +* Get next **day** |
| 190 | + |
| 191 | +```objc |
| 192 | +NSDate *nextDay = [self.gregorain dateByAddingUnit:NSCalendarUnitDay value:1 toDate:date options:0]; |
| 193 | +``` |
| 194 | +
|
| 195 | +* Is date in today/tomorrow/yesterday/weekend |
| 196 | +
|
| 197 | +```objc |
| 198 | +BOOL isToday = [self.gregorian isDateInToday:date]; |
| 199 | +BOOL isYesterday = [self.gregorian isDateInYesterday:date]; |
| 200 | +BOOL isTomorrow = [self.gregorian isDateInTomorrow:date]; |
| 201 | +BOOL isWeekend = [self.gregorian isDateInWeekend:date]; |
| 202 | +``` |
| 203 | + |
| 204 | +* Compare two dates |
| 205 | + |
| 206 | +```objc |
| 207 | + |
| 208 | +BOOL sameDay = [self.gregorian isDate:date1 inSameDayAsDate:date2]; |
| 209 | +// Yes if the date1 and date2 are in same day |
| 210 | + |
| 211 | + |
| 212 | +[self.gregorian compareDate:date1 toDate:date2 toUnitGranularity:unit]; |
| 213 | +// compare the era/year/month/day/hour/minute .etc ... |
| 214 | +// return NSOrderAscending/NSOrderSame/NSOrderDecending |
| 215 | + |
| 216 | +BOOL inSameUnit = [self.gregorian isDate:date1 equalToDate:date2 toUnitGranularity:unit]; |
| 217 | +// if the given unit (era/year/month/day/hour/minute .etc) are the same |
| 218 | + |
| 219 | + |
| 220 | +``` |
0 commit comments