3

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.

Community
  • 1
  • 1
coder1010
  • 412
  • 5
  • 15

1 Answers1

3
// 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

laxonline
  • 2,657
  • 1
  • 20
  • 37