How to change selected segment tintColor of UISegmentedControl in Swift

To programmatically change tint color of segment,

segment.tintColor = UIColor.yellow


Use the code below for above ios 13,

if #available(iOS 13.0, *) {
        segment.selectedSegmentTintColor = .red
} else {
        segment.tintColor = .red
}

if you want to set the color of the title for example, you can do it like this:

let titleTextAttributes = [NSForegroundColorAttributeName: Color.blue]
segmentedControl.setTitleTextAttributes(titleTextAttributes, forState: .Selected)