How can I customize/change color for selected segmented in segmented control? I tried to use method available at UISegmentedControl selected segment color . It worked perfectly with iOS 5 and below but not for iOS 6. Any help is appreciated.
Basically I am looking to change color for the selected segmented to some bright color so that selected/unselected segments are clearly visible.
tintColor = [UIColor redColor]; for (id segment in [button subviews]) { for (id label in [segment subviews]) { if ([label isKindOfClass:[UILabel class]]) { UILabel *titleLabel = (UILabel *) label; [titleLabel setTextColor:[UIColor blackColor]]; } } } UIBarButtonItem *barButtonItem = [[[UIBarButtonItem alloc] ...
To switch between the child view controllers, we use a segmented control. Click the + button in the top right to bring up the Library and add a segmented control to the navigation bar of the master view controller. Open MasterViewController. swift and create an outlet for the segmented control.
We used the approach mentioned by siddarth.
Subclass the segmented controller and overriding the drawrect() method. Something like this:
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
for (int i=0; i<[self.subviews count]; i++)
{
if ([[self.subviews objectAtIndex:i]isSelected] )
{
UIColor *tintcolor=[UIColor redColor];
[[self.subviews objectAtIndex:i] setTintColor:tintcolor];
} else {
UIColor *tintcolor=[UIColor grayColor]; // default color
[[self.subviews objectAtIndex:i] setTintColor:tintcolor];
}
}
}
You can override the subclass of that particular view and then override its drawRect() method for its custom appearance on the screen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With