let mySegmentedControl = UISegmentedControl (items: ["One", "Two", "Three"])
mySegmentedControl.frame = CGRect(x: 0.0, y: 0.0, width: 300, height: 50)
mySegmentedControl.selectedSegmentIndex = 0
mySegmentedControl.addTarget(self, action: #selector(segmentedValueChanged(_:)), for: .valueChanged)
5 Handle value changed:
func segmentedValueChanged(_ sender:UISegmentedControl!) {
print("Selected Segment Index is : \(sender.selectedSegmentIndex)")
}
yourView.addSubview(mySegmentedControl)