Last active
January 21, 2019 18:02
-
-
Save kyleclegg/5144151 to your computer and use it in GitHub Desktop.
Customizing the segmented control to be dark gray and green when selected. Note: this is not a subclass - just set it in your controller.
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
// in viewDidLoad | |
[self.mySegmentedConrol setTintColor:[UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1]]; | |
[self.mySegmentedConrol setSegmentedControlStyle:UISegmentedControlStyleBar]; | |
// Update tints on valueChanged | |
- (IBAction)valueChanged:(UISegmentedControl *)sender { | |
UIColor *selectedTintColor = [UIColor colorWithRed:80.0f/255.0f green:185.0f/255.0f blue:72.0f/255.0f alpha:1.0]; | |
UIColor *unselectedTintColor = [UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1]; | |
for (id subview in [sender subviews]) { | |
if ([subview isSelected]) | |
[subview setTintColor:selectedTintColor]; | |
else | |
[subview setTintColor:unselectedTintColor]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment