How to change the colors of a segment in a UISegmentedControl in iOS 13?

前端 未结 14 846
醉话见心
醉话见心 2020-11-30 18:13

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

14条回答
  •  借酒劲吻你
    2020-11-30 18:37

    Swift version of @Ilahi Charfeddine answer:

    if #available(iOS 13.0, *) {
       segmentedControl.setTitleTextAttributes([.foregroundColor: UIColor.white], for: .selected)
       segmentedControl.selectedSegmentTintColor = UIColor.blue
    } else {
       segmentedControl.tintColor = UIColor.blue
    }
    

提交回复
热议问题