Author Topic: How can I change the text color of a segmented control in Swift?  (Read 25199 times)

kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
To change the text color of all segmented controls in your app, call setTitleTextAttributes on the UISegmentedControl's appearance proxy. For example:
Code: [Select]
UISegmentedControl.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.redColor()], forState: UIControlState.Selected)
To change the text color of an individual segmented control, call setTitleTextAttributes directly on the segmented control object:

Code: [Select]
self.segmentedControl.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.redColor()], forState: UIControlState.Selected)
All the best!
Kevin McNeish
Author of Learn to Code in Swift: https://itunes.apple.com/us/book/learn-to-code-in-swift/id942956811?mt=11