views:

1106

answers:

4

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?

+1  A: 

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

segmentedControl.tintColor = self.navigationController.navigationBar.tintColor;
CajunLuke
+11  A: 

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.

marcc
A: 

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];
DeepDelver
+1  A: 

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.

Rafael
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