Question: Before asking the question, I have searched stackoverflow, find a related post:

[change segmentControl border color](https://stackoverflow.com/questions/19041035/iphone-ios7-segmented-uisegmentedcontrol-change-only-border-color) 

But we can see it is in `objective-c` language.

So how can we change the borderColor of `UISegmentControl` in `swift` ?

Answer: 
More simple approach:

```
segmentControl.layer.borderWidth = 1.0
segmentControl.layer.cornerRadius = 5.0
segmentControl.layer.borderColor = UIColor.red.cgColor
segmentControl.layer.masksToBounds = true

```
We can set the background image to achieve the effect.

```
    let customSegmentedControl = UISegmentedControl.appearance()
    //customSegmentedControl.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.red], for: UIControlState.normal)

    customSegmentedControl.setBackgroundImage(UIImage.init(named: "ni2.png"), for: .normal, barMetrics: .default)
    customSegmentedControl.setBackgroundImage(UIImage.init(named: "ni.png"), for: .selected, barMetrics: .default)

```