I need a little help ... I have a custom UIVIew Class where inside there is a collectionView showing a calendar with every day of the month.
My collectionView works perfectly, at the top of the collectionView there are two UIButtons that allow the user to show next months or previous months.
Now, I would like to see the next or previous days the user can view them by scrolling through the collectionView by separating each month with a Paging.
Here I show you the code used to navigate through the months
#pragma mark -
#pragma mark NEXT / PREVIOUS MONTH FUNCTION
-(NSDate *)nextMonth {
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
dateComponents.month = 1;
return [calendar dateByAddingComponents:dateComponents toDate:self.currentMonth options:0];
}
- (NSDate *)previousMonth {
NSInteger addValue = -1;
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *dateComponents = [NSDateComponents new];
dateComponents.month = addValue;
return [calendar dateByAddingComponents:dateComponents toDate:self.currentMonth options:0];
}
- (IBAction)prev:(id)sender {
self.currentMonth = [self previousMonth];
[_calendarCollectionView reloadData];
}
- (IBAction)add:(id)sender {
self.currentMonth = [self nextMonth];
[_calendarCollectionView reloadData];
}
Here are the methods of my UICollectionView
#pragma mark -
#pragma mark COLLECTIONVIEW DATA SOURCE
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
// Calcola il numero delle settimane
NSRange rangeOfWeeks = [[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitWeekOfMonth inUnit:NSCalendarUnitMonth forDate:[self firstDayOfMonth]];
NSUInteger numberOfWeeks = rangeOfWeeks.length;
NSInteger numberOfItems = numberOfWeeks * 7;
return numberOfItems;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"dayCell";
UPCalendarCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
NSDateFormatter *formatter = [NSDateFormatter new];
formatter.dateFormat = @"d";
cell.dayLabel.text = [formatter stringFromDate:[self dateForCellAtIndexPath:indexPath]];
// Trova il giorno corrente e cerchialo
[cell highlitedDay];
// Trova tutti i giorni PRIMA del primo giorno del Mese ed evidenziali
if ([self dateForCellAtIndexPath:indexPath] < self.firstDayOfMonth) cell.dayLabel.textColor = [self disableDayColor];
// Trova tutti i giorni DOPO l'ultimo giorno del Mese ed evidenziali
if ([self dateForCellAtIndexPath:indexPath] > [self lastDayOfMonth]) cell.dayLabel.textColor = [self disableDayColor];
return cell;
}
How can I get all this? Can you help me with that example?