JoJo
JoJo

Reputation: 20115

How do you make the selected segment of a UISegmentedControl darker?

I'm using UIAppearance to set global styles for my iOS app. I am envisioning a light gray style.

[[UINavigationBar appearance]
    setTintColor:[UIColor colorWithWhite:0.95 alpha 1.0]
];

[[UISegmentedControl appearance]
    setTintColor:[UIColor colorWithWhite:0.90 alpha 1.0]
];

enter image description here

The problem is that the selected segment (Uno) of the UISegmentedControl is not much darker than a normal segment (Dos). The normal segment is already at the right darkness, but I would like to only darken the selected segment, so people can tell the difference between the two. Darkening tint would darken both of them at the same time, so that won't work.

Upvotes: 3

Views: 1004

Answers (1)

Kyle Richter
Kyle Richter

Reputation: 450

The easiest way to do it is to iterate through a list of the subviews for a segmented controller and see which one is selected, when you find a selected subview you will need to adjust its tint color darker.

for (int x= 0; x <[aSegementedController.subviews count]; x++) 
{
    UIBarButtonItem *subview = [aSegementedController.subviews objectAtIndex:x];
    if ([subview isSelected]) 
    {               

        [subview setTintColor:darkerColor];
    }
}

This however doesn't work with UIAppearance, I do not believe it is customizable at that level.

Upvotes: 1

Related Questions