Is there any way to customize color of selected segment in UISegmentedControl
?
I've found segmentedController.tintColor
property, which lets me customize color of the whole segmented control. The problem is, when I select bright color for tintColor
property, selected segment becomes almost unrecognizable (its color is almost the same as the rest of segmented control, so its hard to distinguish selected and unselected segments). So I cannot use any good bright colors for segmented control. The solution would be some separate property for selected segment color but I cannot find it. Did anyone solve this?
To change the color/font of the selected segment titles, use setTitleTextAttributes with a state of . selected / UIControlStateSelected . If you create a segmented control with images, if the images are created as template images, then the segmented control's tintColor will be used to color the images.
Use segmented controls to view similar content in different ways and the changes should take effect immediately when a segmented control option is selected. They should never require a user to click a button to apply the settings. Don't use a segmented control for action, such as add and remove.
Here is the absolute simplest way to change the selected segment to any RGB color. No subclassing or hacks required.
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; UIColor *newTintColor = [UIColor colorWithRed: 251/255.0 green:175/255.0 blue:93/255.0 alpha:1.0]; segmentedControl.tintColor = newTintColor; UIColor *newSelectedTintColor = [UIColor colorWithRed: 0/255.0 green:175/255.0 blue:0/255.0 alpha:1.0]; [[[segmentedControl subviews] objectAtIndex:0] setTintColor:newSelectedTintColor];
This example shows the important steps:
Notes:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With