Question: I have a segmented control with 8 segments. I can change the default tintColor of the whole control, BUT can I set a different color for each segment in the control? I found a tutorial that worked in 5.1 with a new class that calls this method, “-(void)setTintColor:(UIColor*)color forTag:(NSInteger)aTag” But it doesn’t work in iOS 6. Any ideas?
Answer:
Its a hacky fix. This will work. Place your code in ViewDidAppear. That will do the trick.
[sourcecode language=”objc”]
– (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
dispatch_async(dispatch_get_main_queue(),^{
for (int i=0; i<[segmentControl.subviews count]; i++)
{
if ([[segmentControl.subviews objectAtIndex:i]isSelected] )
{
[[segmentControl.subviews objectAtIndex:i] setTintColor:[UIColor blackColor]];
break;
}
}
});
}
[/sourcecode]
Leave a Reply