How do I switch UISegmentedControl
programmatically?
The selectedSegmentIndex property identifies the selected segment of a UISegmentedControl. Set this property to the any valid segment index, or UISegmentedControlNoSegment (-1) to turn off the current selection.
// select the first segment
segmented.selectedSegmentIndex = 0;
// turn off the current selection
segmented.selectedSegmentIndex = UISegmentedControlNoSegment;
Alternatively, after you have changed the selectedSegmentIndex call 'sendActionsForControlEvents:' for example
segmentedControl.selectedSegmentIndex = 0
[segmentedControl sendActionsForControlEvents:UIControlEventValueChanged];
SWIFT 5:
segmentedControl.selectedSegmentIndex = 0
segmentedControl.sendActions(for: .valueChanged)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With