Search code examples
iosswiftswift4uisegmentedcontrol

selected SegmentedControl's font separately


I am developing an iOS app using swift, and i would like to change the selected SegmentedControl's font, only the selected one, i have found already how to change the font for all the segments but i am looking for a way to do it separately, like for example bold only for the selected segment.

this is how to do it for all segments in UISegmentedControl :

let attr = NSDictionary(object: UIFont(name: "OpenSans", size: 12.0)!, forKey: NSFontAttributeName as NSCopying)
UISegmentedControl.appearance().setTitleTextAttributes(attr as [NSObject : AnyObject] , for: .normal)

Solution

  • You can use setTitleTextAttributes for UIControlState just use not .normal but .selected