12

The tint that usually shows on a UISegmentedControl on the selected button isn't showing when I set the whole nav bar to black (self.navigationController.navigationBar.tintColor = [UIColor blackColor];).

Is this a bug or something I'm missing?

6 Answers 6

59

In order for the tint color to show, there are a couple of requirements:

segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;

It's required for the tintColor to work.

You also mention that you have the tintColor set to [UIColor blackColor]. Unfortunately, the UISegmentedControl will always display the selected segment with a darker color, never a lighter. Try setting your tintColor to [UIColor darkGrayColor] and you should be able to see the selected segment change color.

2

Have you tried setting the tint on the segmented control separately?

segmentedControl.tintColor = self.navigationController.navigationBar.tintColor;
2

Try using tint color [UIColor colorWithWhite:80.0/255.0 alpha:1.0]. This makes the black color less black and allows the selected segment to become darker after selection. You can set the white component as suitable.

Sample code:

UISegmentedControl *aSegmentedControl = [[UISegmentedControl alloc] initWithItems:arrItems];
aSegmentedControl.frame = CGRectMake(55, 382, 210, 32);
aSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
aSegmentedControl.selectedSegmentIndex = 0;
aSegmentedControl.tintColor = [UIColor colorWithWhite:80.0/255.0 alpha:1.0];
2

On iphone 3.0, if you want add the Segmented Control in a NavigationController, do that first and change the tintcolor after u did that.

1
  • This is helpful, but in my case I was setting the segmented control into the navitem in viewDidLoad and then immediately setting the tint color. I found I had to move the tintColor set to viewWillAppear and then it finally worked.
    – Jason
    Commented Sep 23, 2010 at 17:54
2

If you are seeing different tint colors on the nav bar, you may also want to use the momentary property on your uisegmentedcontrol.

segmentedControl.momentary=YES;

This clears the highlight tint from the control.

1

Change the segmented control style to Bar or Bezeled in the Attributes Inspector. That's all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.