UISegmentedControl selected segment color

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:

  1. Sets the control style to "StyleBar", which is required for it to work
  2. Sets the un-selected color for the entire control first to orange
  3. Sets the color of the selected segment to green

Notes:

  • Steps 1 and 2 can be done in interface builder, or in code as shown. However step 3 can only be done in code
  • The color values being set with notation like this "123.0/255.0" is just a way to make the RGB values stand out instead the normalized float values required by UIColor (just ignore it if you like)

I found A Simple Way to Add Color for Selected Segment in UISegmentcontrol

sender is UISegmentControl

for (int i=0; i<[sender.subviews count]; i++) 
{
    if ([[sender.subviews objectAtIndex:i]isSelected] ) 
    {               
    UIColor *tintcolor=[UIColor colorWithRed:127.0/255.0 green:161.0/255.0 blue:183.0/255.0 alpha:1.0];
    [[sender.subviews objectAtIndex:i] setTintColor:tintcolor];
    }
   else 
    {
        [[sender.subviews objectAtIndex:i] setTintColor:nil];
    }
}

Check its Working For Me