5

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.

Community
  • 1
  • 1
user1140780
  • 988
  • 2
  • 13
  • 29

2 Answers2

4

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];
    }
   }

}
user1140780
  • 988
  • 2
  • 13
  • 29
3

You can override the subclass of that particular view and then override its drawRect() method for its custom appearance on the screen.

kidsid49
  • 1,358
  • 3
  • 18
  • 37