Created
February 11, 2015 21:26
-
-
Save thomasdegry/2e0e1955379d6500cafa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)constructButtons { | |
self.numberOfMonths = 1 + self.pastOffset + self.futureOffset; | |
NSMutableArray *buttons = [[NSMutableArray alloc] init]; | |
// Loop from i - self.pastOffset to i <= self.futureOffset + 1 to include start month | |
for ( int i = -[[NSNumber numberWithInteger:self.pastOffset] intValue]; i <= self.futureOffset + 1; i++ ) { | |
NSDateComponents *offSetComponents = [[NSDateComponents alloc] init]; | |
UIButton *button = [[UIButton alloc] initWithFrame:CGRectZero]; | |
button.translatesAutoresizingMaskIntoConstraints = NO; | |
[offSetComponents setMonth:i]; | |
NSDate *previousMonth = [[NSCalendar currentCalendar] dateByAddingComponents:offSetComponents toDate:self.startDate options:0]; | |
NSString *formattedString = [DateFactory shortMonthFromDate:previousMonth]; | |
NSLog(@"formatted month %@", formattedString); | |
[button setTitle:[DateFactory shortMonthFromDate:previousMonth] forState:UIControlStateNormal]; | |
[button setTitleColor:[UIColor blackColor] forState:UIControlStateSelected]; | |
[button setTitleColor:[UIColor colorWithRed: 0.682 green: 0.682 blue: 0.682 alpha: 1] forState:UIControlStateNormal]; | |
[button setBackgroundColor:[UIColor redColor]]; | |
[self.buttonWrapper addSubview:button]; | |
[buttons addObject:button]; | |
CGFloat multiplier = 1 / [[NSNumber numberWithInteger:self.numberOfMonths] floatValue]; | |
[button mas_makeConstraints:^(MASConstraintMaker *make) { | |
make.height.equalTo(self.buttonWrapper.mas_height); | |
make.width.equalTo(self.buttonWrapper.mas_width).multipliedBy(multiplier); | |
make.leading.equalTo(self.buttonWrapper.mas_leading); | |
make.centerY.equalTo(self.buttonWrapper.mas_centerY); | |
}]; | |
} | |
self.buttons = buttons; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment