What you need to understand is that the backgroundColor property is not stateful. Therefore, you should use setBackgroundImage(_:for:barMetrics:) .
We can easily remove both borders and delimiters using the function below.
For Swift 3 & 4+:
extension UISegmentedControl { func removeBorders() { setBackgroundImage(imageWithColor(color: backgroundColor!), for: .normal, barMetrics: .default) setBackgroundImage(imageWithColor(color: tintColor!), for: .selected, barMetrics: .default) setDividerImage(imageWithColor(color: UIColor.clear), forLeftSegmentState: .normal, rightSegmentState: .normal, barMetrics: .default) }
For Swift 2.2:
extension UISegmentedControl { func removeBorders() { setBackgroundImage(imageWithColor(backgroundColor!), forState: .Normal, barMetrics: .Default) setBackgroundImage(imageWithColor(tintColor!), forState: .Selected, barMetrics: .Default) setDividerImage(imageWithColor(UIColor.clearColor()), forLeftSegmentState: .Normal, rightSegmentState: .Normal, barMetrics: .Default) }
Call the above function.
segmentedControl.removeBorders()
Link: Remove UISegmentedControl delimiters completely. (iphone)
Thanks https://stackoverflow.com/users/3921490/amagain for version Swift 3.
Sohil R. memon
source share