David David - 3 months ago 15
iOS Question

Switch to the first tab of UISegmentedControl programmatically

I made an iOS app with Xcode and Swift.

Does anybody know how to switch to the first (or another) tab of UISegmentedControl programmatically e.g. by clicking a button or so?

Answer

UISegmentedControl has property named selectedSegmentIndex.

Change it's value in this way:

segmentedControl.selectedSegmentIndex = 0