I'm trying to add a subview below my UISegmentedControl from an extension so when I add more properties to this subview it can be reused from other UISegmentedControls within the app.

It appears in the right place, but for some reason sometimes appears above some segments and sometimes below. Am I missing something?

[![enter image description here](https://i.stack.imgur.com/XoeeU.png)](https://i.stack.imgur.com/XoeeU.png)

So far in my extension, that's what I have:

```
import UIKit

extension UISegmentedControl {
    func addBackgroundView() {
        let backgroundView = UIView();
        backgroundView.frame = self.bounds;
        backgroundView.backgroundColor = UIColor.purple;
        self.insertSubview(backgroundView, belowSubview: self);
    }
}

```

And then, I call the extensions function from the viewDidLoad method in the ViewController:

```
self.segmentedControlUnit.addBackgroundView();

```