Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISegmentedControl different font color for selected and unselected segments [duplicate]

Possible Duplicate:
How to change font color of UISegmentedControl

Is it possible to keep different font colors for the text of selected and unselected segment of UISegmentedControl. Any help will be appreciated.

like image 864
coder1010 Avatar asked Dec 05 '25 02:12

coder1010


1 Answers

// Instantiate as usual
NSArray *items = [NSArray arrayWithObjects:@"first", @"second", [UIImage imageNamed:@"image.png"], nil];
MCSegmentedControl *segmentedControl = [[MCSegmentedControl alloc] initWithItems:items];

// set frame, add to view, set target and action for value change as usual
segmentedControl.frame = CGRectMake(10.0f, 10.0f, 300.0f, 44.0f);
[self.view addSubview:segmentedControl];
[segmentedControl addTarget:self action:@selector(segmentedControlDidChange:) forControlEvents:UIControlEventValueChanged];

// Set a tint color
segmentedControl.tintColor = [UIColor orangeColor];

// Customize font and items color
segmentedControl.selectedItemColor = [UIColor yellowColor];
segmentedControl.unselectedItemColor = [UIColor darkGrayColor];

If you use Interface Builder, add a normal UISegmentedControl, set its class as MCSegmentedControl in the Identity Inspector, set the Tint in the Attributes Inspector.

At the moment, animations and the following UISegmentedControl methods are not supported:

- (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment;
- (void)setContentOffset:(CGSize)offset forSegmentAtIndex:(NSUInteger)segment

Here are the files:

MCSegmentedControl.zip

like image 166
laxonline Avatar answered Dec 07 '25 18:12

laxonline



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!