A UISegmentedControl
has a new appearance in iOS 13 and existing code to alter the colors of the segmented control no longer work as they did.
Prior to iOS 13 you could set the tintColor
and that would be used for the border around the segmented control, the lines between the segments, and the background color of the selected segment. Then you could change the color of the titles of each segment using the foreground color attribute with titleTextAttributes
.
Under iOS 13, the tintColor
does nothing. You can set the segmented control's backgroundColor
to change the overall color of the segmented control. But I can't find any way to alter the color used as the background of the selected segment. Setting the text attributes still works. I even tried setting the background color of the title but that only affects the background of the title, not the rest of the selected segment's background color.
In short, how do you modify the background color of the currently selected segment of a UISegmentedControl
in iOS 13? Is there a proper solution, using public APIs, that doesn't require digging into the private subview structure?
There are no new properties in iOS 13 for UISegmentedControl
or UIControl
and none of the changes in UIView
are relevant.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…