Segmented Subview Control from Extension
I'm trying to add a subview below my UISegmentedControl from an extension, so when I add additional properties to this subtask, it can be reused from other UISegmentedControls in the application.
It appears in the right place, but for some reason it sometimes appears above some segments, and sometimes below. Did I miss something?
So far in my extension, what I have is:
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();
+3
source to share
2 answers