I'm quite late to the party, but here's what I'd do:
Set the background color to .clear
segmentedControlInstance.backgroundColor = UIColor(red:0.13, green:0.16, blue:0.29, alpha:1.0)
Set the background tint color to .clear
segmentedControlInstance.tintColor = .clear
I noticed the selected segment's title is bold. Set the text attributes for the two states (.normal & .selected)
segmentedControlInstance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 16)], for: .normal)
segmentedControlInstance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 16)], for: .selected)
Finally, set the two background images. Caution, I have no idea what to set for the barMetrics parameter:
segmentedControlInstance.setBackgroundImage(UIImage(name: "selectedSegment", for: .selected, barMetrics: ?)
segmentedControlInstance.setBackgroundImage(UIImage(name: "normalSegment", for: .normal, barMetrics: ?)
I'll let you play around with the barMetrics parameters.
If what I need to customize wasn't on this list, UISegmentedControl Docs , I'd build my own.
In your image, I'd use two buttons, a view for the indicator, and some logic to respond to user interactions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.