Set UISegmentedControl selected segment color

Previously in order to set selected segment color in UISegmentControl we needed to loop through subviews and set the right one like this

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];
    }
}

imagine the uncertainties 😀

But since Xcode 11+ we can directly set selected tint in storyboard like this.

selectedSegmentTintColor

In iops 13 + we can also use selectedSegmentTintColor. Makes life easy.

NEED A JOB? NEED TO HIRE? NEED HELP?

Join group of Software Professionals

iOS DEVELOPER’S DEN