UISegmentedControl Selected Tint Not Showing
The tint that usually sho开发者_高级运维ws 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?
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.
Have you tried setting the tint on the segmented control separately?
segmentedControl.tintColor = self.navigationController.navigationBar.tintColor;
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];
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.
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.
Change the segmented control style to Bar or Bezeled in the Attributes Inspector. That's all.
精彩评论