Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISegmentedControl Selected Tint Not Showing

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?

like image 377
Ternary Avatar asked Dec 12 '09 19:12

Ternary


People also ask

How do you change the segment control color?

To change the color/font of the selected segment titles, use setTitleTextAttributes with a state of . selected / UIControlStateSelected . If you create a segmented control with images, if the images are created as template images, then the segmented control's tintColor will be used to color the images.

How do you customize segmented controls in swift?

First, we need to create our variable:Three variables to customize our view with a default value. Now we need to put our buttons in view but we have an array and this can be unlimited. The best to do this is create a Horizontal Stack View. Stack View makes the subViews with equal spacing without using any constraint.


2 Answers

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.

like image 103
marcc Avatar answered Oct 19 '22 22:10

marcc


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

segmentedControl.tintColor = self.navigationController.navigationBar.tintColor;
like image 41
Cajunluke Avatar answered Oct 20 '22 00:10

Cajunluke