// // ButtonsViewController.m // FSCalendar // // Created by dingwenchao on 4/15/16. // Copyright © 2016 wenchaoios. All rights reserved. // #import "ButtonsViewController.h" @interface ButtonsViewController () @end @implementation ButtonsViewController - (instancetype)init { self = [super init]; if (self) { self.title = @"FSCalendar"; } return self; } - (void)loadView { UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; view.backgroundColor = [UIColor groupTableViewBackgroundColor]; self.view = view; // 450 for iPad and 300 for iPhone CGFloat height = [[UIDevice currentDevice].model hasPrefix:@"iPad"] ? 450 : 300; FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 64, view.frame.size.width, height)]; calendar.dataSource = self; calendar.delegate = self; calendar.backgroundColor = [UIColor whiteColor]; calendar.appearance.headerMinimumDissolvedAlpha = 0; calendar.appearance.caseOptions = FSCalendarCaseOptionsHeaderUsesUpperCase; [self.view addSubview:calendar]; self.calendar = calendar; UIButton *previousButton = [UIButton buttonWithType:UIButtonTypeCustom]; previousButton.frame = CGRectMake(5, 64+5, 90, 34); previousButton.backgroundColor = [UIColor whiteColor]; [previousButton setTitleColor:self.calendar.appearance.headerTitleColor forState:UIControlStateNormal]; [previousButton setTitle:@"PREV" forState:UIControlStateNormal]; previousButton.titleLabel.font = [UIFont systemFontOfSize:15]; previousButton.layer.cornerRadius = 3; previousButton.layer.borderWidth = 1; previousButton.clipsToBounds = YES; previousButton.layer.borderColor = self.calendar.appearance.headerTitleColor.CGColor; [previousButton addTarget:self action:@selector(previousClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:previousButton]; self.previousButton = previousButton; UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeCustom]; nextButton.frame = CGRectMake(CGRectGetWidth(self.view.frame)-90-5, 64+5, 90, 34); nextButton.backgroundColor = [UIColor whiteColor]; [nextButton setTitleColor:self.calendar.appearance.headerTitleColor forState:UIControlStateNormal]; [nextButton setTitle:@"NEXT" forState:UIControlStateNormal]; nextButton.titleLabel.font = [UIFont systemFontOfSize:15]; nextButton.layer.cornerRadius = 3; nextButton.layer.borderWidth = 1; nextButton.clipsToBounds = YES; nextButton.layer.borderColor = self.calendar.appearance.headerTitleColor.CGColor; [nextButton addTarget:self action:@selector(nextClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:nextButton]; self.nextButton = nextButton; } - (void)previousClicked:(id)sender { NSDate *currentMonth = self.calendar.currentPage; NSDate *previousMonth = [self.calendar dateBySubstractingMonths:1 fromDate:currentMonth]; [self.calendar setCurrentPage:previousMonth animated:YES]; } - (void)nextClicked:(id)sender { NSDate *currentMonth = self.calendar.currentPage; NSDate *nextMonth = [self.calendar dateByAddingMonths:1 toDate:currentMonth]; [self.calendar setCurrentPage:nextMonth animated:YES]; } @end