Created
April 17, 2015 22:09
-
-
Save jungchris/5dbf9ec6da13834bc5b5 to your computer and use it in GitHub Desktop.
Objective-C Code to Create an NSArray of Configured UIButtons
This file contains 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
// Create array of Status Indicator UIButtons based on Andrew's 'configuredButton' method | |
- (void)defineStatusIndicatorButtons { | |
CGRect r = CGRectMake(0, 0, [[self.columnPlacementArray objectAtIndex:0] floatValue] + kButtonOffsetX, [[self.rowPlacementArray objectAtIndex:0] floatValue] + kButtonOffsetY); | |
self.arrayInfoButtons = [NSMutableArray arrayWithObjects: | |
(self.buttonStatusIndicatorPS = [self configuredStatusButton:r normalTitle:@"S" highlightTitle:@"possSm"]), | |
(self.buttonStatusIndicatorPM = [self configuredStatusButton:r normalTitle:@"M" highlightTitle:@"possMd"]), | |
(self.buttonStatusIndicatorPL = [self configuredStatusButton:r normalTitle:@"L" highlightTitle:@"possLg"]), | |
(self.buttonStatusIndicatorSS = [self configuredStatusButton:r normalTitle:@"S" highlightTitle:@"saleSm"]), | |
(self.buttonStatusIndicatorSM = [self configuredStatusButton:r normalTitle:@"M" highlightTitle:@"saleMd"]), | |
(self.buttonStatusIndicatorSL = [self configuredStatusButton:r normalTitle:@"L" highlightTitle:@"saleLg"]), | |
(self.buttonStatusIndicatorCS = [self configuredStatusButton:r normalTitle:@"S" highlightTitle:@"cultSm"]), | |
(self.buttonStatusIndicatorCM = [self configuredStatusButton:r normalTitle:@"M" highlightTitle:@"cultMd"]), | |
(self.buttonStatusIndicatorPar = [self configuredStatusButton:r normalTitle:@"A" highlightTitle:@"paraSm"]), | |
nil]; | |
} | |
// Button constructor for defineStatusIndicatorButtons | |
- (UIButton *)configuredStatusButton:(CGRect)r normalTitle:(NSString *)normal highlightTitle:(NSString *)highlight { | |
UIButton *buttonIdentifier = [UIButton buttonWithType:UIButtonTypeSystem]; | |
[buttonIdentifier addTarget:self action:@selector(selectorForStatusIndicatorButton:) forControlEvents:UIControlEventTouchUpInside]; | |
// set appearance | |
[buttonIdentifier setBackgroundColor:[UIColor whiteColor]]; | |
[buttonIdentifier setTitle:normal forState:UIControlStateNormal]; | |
[buttonIdentifier setTitle:@"" forState:UIControlStateSelected]; | |
[buttonIdentifier setTitle:highlight forState:UIControlStateHighlighted]; | |
[buttonIdentifier setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | |
((UIButton *)buttonIdentifier).layer.cornerRadius = 8; | |
// add to subview | |
[self.view addSubview:buttonIdentifier]; | |
return buttonIdentifier; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment