Home:ALL Converter>customize color for selected segmented in segmented control

customize color for selected segmented in segmented control

Ask Time:2012-10-17T11:57:40         Author:user1140780

Json Formatter

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.

Author:user1140780,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12926884/customize-color-for-selected-segmented-in-segmented-control
user1140780 :

We used the approach mentioned by siddarth. \n\nSubclass the segmented controller and overriding the drawrect() method. Something like this:\n\n- (void)drawRect:(CGRect)rect\n{\n[super drawRect:rect];\n\nfor (int i=0; i<[self.subviews count]; i++)\n{\n if ([[self.subviews objectAtIndex:i]isSelected] )\n {\n UIColor *tintcolor=[UIColor redColor];\n [[self.subviews objectAtIndex:i] setTintColor:tintcolor];\n } else {\n UIColor *tintcolor=[UIColor grayColor]; // default color\n [[self.subviews objectAtIndex:i] setTintColor:tintcolor];\n }\n }\n\n}\n",
2012-10-17T20:38:17
yy