I wrote this handy little function to change the font color of a UISegmentedControl and it works perfectly, even having a different foont color depending on the active segment.
The problem is I would rather it be a little more generic in that I am currently looking at the value of the label to determine if the current segment in the loop is the active segment.
when looping through the segments, it doesn't necessarily loop through in order and I can't figure out how to tell if the current segment is the active segment, without checking the name.
Anyone have any ideas on how to tell if a given subview is the active segment subview?
Code:
+(void)setFontColorForSegment:(UISegmentedControl *)segment:(NSArray *)values
{
if(values==nil)
values = [NSArray arrayWithObjects:@"All", @"Cash Games", @"Tournaments", nil];
for (id seg in [segment subviews]) {
for (id label in [seg subviews])
if([label isKindOfClass:[UILabel class]]) {
UILabel *temp = label;
if(![temp.text isEqualToString:[values stringAtIndex:segment.selectedSegmentIndex]]) {
[label setTextColor:[UIColor colorWithRed:.2 green:.2 blue:.2 alpha:1]];
[label setShadowColor:[UIColor whiteColor]];
[label setShadowOffset:CGSizeMake(-1.0, -1.0)];
} else {
[label setTextColor:[UIColor whiteColor]];
[label setShadowColor:[UIColor blackColor]];
[label setShadowOffset:CGSizeMake(2.0, 2.0)];
}
}
}
}