I want to set colors for the text and background of UISegmentedControl. So I've four colors to set, the default and selected color of the text and background.
I can use tintColor
and backgroundColor
to set the background. But how to set the default text color, not same as the tint color?
Note: here is swift3 not the older language. I'm a beginner of ios, I just start from the swift3, have no experience of the former language.
Any help will be appreciated.
Swift 4.2 + code to update text color for your UISegmentedControl
(sc
in example bellow):
// selected option color
sc.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.green], for: .selected)
// color of other options
sc.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white], for: .normal)