102 lines
2.8 KiB
Objective-C
102 lines
2.8 KiB
Objective-C
//
|
|
// FSCalendarScopeExampleViewController.m
|
|
// FSCalendar
|
|
//
|
|
// Created by Wenchao Ding on 8/29/15.
|
|
// Copyright (c) 2015 wenchaoios. All rights reserved.
|
|
//
|
|
|
|
#import "FSCalendarScopeExampleViewController.h"
|
|
|
|
@implementation FSCalendarScopeExampleViewController
|
|
|
|
#pragma mark - Life cycle
|
|
|
|
- (void)viewDidLoad
|
|
{
|
|
[super viewDidLoad];
|
|
[_calendar selectDate:[NSDate date]];
|
|
|
|
_calendar.scopeGesture.enabled = YES;
|
|
|
|
self.dateFormatter = [[NSDateFormatter alloc] init];
|
|
self.dateFormatter.dateFormat = @"yyyy/MM/dd";
|
|
|
|
// Uncomment this to perform an 'initial-week-scope'
|
|
// _calendar.scope = FSCalendarScopeWeek;
|
|
}
|
|
|
|
- (void)dealloc
|
|
{
|
|
NSLog(@"%s",__FUNCTION__);
|
|
}
|
|
|
|
|
|
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
|
|
{
|
|
_calendarHeightConstraint.constant = CGRectGetHeight(bounds);
|
|
[self.view layoutIfNeeded];
|
|
}
|
|
|
|
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition
|
|
{
|
|
NSLog(@"did select date %@",[self.dateFormatter stringFromDate:date]);
|
|
|
|
NSMutableArray *selectedDates = [NSMutableArray arrayWithCapacity:calendar.selectedDates.count];
|
|
[calendar.selectedDates enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
|
|
[selectedDates addObject:[self.dateFormatter stringFromDate:obj]];
|
|
}];
|
|
NSLog(@"selected dates is %@",selectedDates);
|
|
|
|
}
|
|
|
|
- (void)calendarCurrentPageDidChange:(FSCalendar *)calendar
|
|
{
|
|
NSLog(@"%s %@", __FUNCTION__, [self.dateFormatter stringFromDate:calendar.currentPage]);
|
|
}
|
|
|
|
#pragma mark - <UITableViewDataSource>
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
{
|
|
return 2;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
NSString *identifier = @[@"cell_month",@"cell_week"][indexPath.row];
|
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
|
|
return cell;
|
|
}
|
|
|
|
#pragma mark - <UITableViewDelegate>
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
FSCalendarScope selectedScope = indexPath.row == 0 ? FSCalendarScopeMonth : FSCalendarScopeWeek;
|
|
[_calendar setScope:selectedScope animated:_animationSwitch.on];
|
|
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
|
{
|
|
return 20;
|
|
}
|
|
|
|
- (IBAction)toggleClicked:(id)sender
|
|
{
|
|
if (self.calendar.scope == FSCalendarScopeMonth) {
|
|
[self.calendar setScope:FSCalendarScopeWeek animated:_animationSwitch.on];
|
|
} else {
|
|
[self.calendar setScope:FSCalendarScopeMonth animated:_animationSwitch.on];
|
|
}
|
|
}
|
|
|
|
@end
|