Is it possible to have each segment in a UISegmentedControl
's text / font colour to be different?
I see to be able to only set the global colour and this is not what I am looking for.
Is it possible to have each segment in a UISegmentedControl
's text / font colour to be different?
I see to be able to only set the global colour and this is not what I am looking for.
Yes, you can set different colours for each segment, try the below code.....
// assuming there are 3 segments
// background colour
for (int i = 0; i < [segmentControl.subviews count]; i++)
{
UIColor *tintcolor = nil;
if (i == 0)
tintcolor = [UIColor blueColor];
else if (i == 1)
tintcolor = [UIColor greenColor];
else if (i == 2)
tintcolor = [UIColor redColor];
[segmentControl.subviews[i] setTintColor:tintcolor];
}
// text color
for (id segmentControl in [self.segmentedControl subviews])
{
for (id label in [segmentControl subviews])
{
if ([label isKindOfClass:[UILabel class]])
[label setTextColor:[UIColor darkGrayColor]]; // here you can set whatever colour you want
}
}
[segmentControl setNeedsDisplay];