Skip to content

Instantly share code, notes, and snippets.

@kyleclegg
Last active January 21, 2019 18:02
Show Gist options
  • Save kyleclegg/5144151 to your computer and use it in GitHub Desktop.
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.
// 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