Its easy change the color of UISegmentedControl. I found various solution like this, this site and the best this solution. But none was what I want.
I tried create a
I Think there is a lot easier solution. Just clean the pointers..
for (int i=0; i<[self.segmentedControll.subviews count]; i++)
{
[[self.segmentedControll.subviews objectAtIndex:i] setTintColor:nil];
if (![[self.segmentedControll.subviews objectAtIndex:i]isSelected])
{
UIColor *tintcolor=[UIColor blackColor];
[[self.segmentedControll.subviews objectAtIndex:i] setTintColor:tintcolor];
}
else
{
UIColor *tintcolor=[UIColor blueColor];
[[self.segmentedControll.subviews objectAtIndex:i] setTintColor:tintcolor];
}
}
Wow... When we write were in stackoverflow, we can calm down and think better. I write the answer in my ow question:
If I go from right to left it not happens.
This is the solution! What I have to do? Simulate this.
BOOL inside = FALSE;
- (void)changeColor{
int old = segmentedControl.selectedSegmentIndex;
for (int i=0; i<3; i++) {
[segment[i] setTintColor:[UIColor lightGrayColor]];
}
/**/inside = TRUE;
/**/for (int i=3; i>0; i--) {
/**/ //When I do this, it call "segmentedControl:"
/**/ [segmentedControl setSelectedSegmentIndex:i];
/**/}
/**/int select = old;
[segment[select] setTintColor:[UIColor blueColor]];
[segmentedControl setSelectedSegmentIndex:select];
/**/inside = FALSE;
}
- (void)segmentedControl:(id)sender
{
/**/if (inside==TRUE) return; //Ignore this calls.
//do some thing
[self changeColor];
}