Environment
- macOS 15.7.3
- Xcode 26.1.1 / 26.2
- iOS 18.5 / 26.2
- iPhone 16 Pro Simulator and physical device
Problem Description
When tapping an unselected UISegmentedControl, the selected segment does not match the tapped position. Specifically, tapping the rightmost segment (index: 3) results in the leftmost segment (index: 0) being selected instead.
Conditions for Reproduction
This issue occurs when all of the following conditions are met:
- Built with Xcode 26.x
UIDesignRequiresCompatibilityis set toYESin Info.plistUISegmentedControlis positioned using Auto Layout with leading alignment- Segments are added dynamically using
insertSegment(withTitle:at:animated:)
Note: The issue does not occur when segments are defined statically in Storyboard.
Steps to Reproduce
- Create a subclass of
UISegmentedControlthat dynamically sets segments:
class CustomSegmentedControl: UISegmentedControl {
func setSegments(titles: [String]) {
removeAllSegments()
titles.forEach { title in
insertSegment(withTitle: title, at: numberOfSegments, animated: false)
}
}
}
- In the ViewController, configure the control:
override func viewDidLoad() {
super.viewDidLoad()
segmentedControl.setSegments(titles: ["Item A", "Item B", "Item C", "Item D"])
segmentedControl.selectedSegmentIndex = UISegmentedControl.noSegment
}
- Set
UIDesignRequiresCompatibilitytoYESin Info.plist:
<key>UIDesignRequiresCompatibility</key>
<true/>
- Run the app and tap the rightmost segment ("Item D")
Expected vs Actual Behavior
| Tap rightmost segment | "Item D" (index: 3) is selected | "Item A" (index: 0) is selected |
What I Tried (Did Not Work)
Calling layoutIfNeeded() after adding segments:
segmentedControl.setSegments(titles: ["Item A", "Item B", "Item C", "Item D"])
segmentedControl.layoutIfNeeded() // No effect
Workarounds
- Set
UIDesignRequiresCompatibilitytoNO(enables Liquid Glass design) - Define segments statically in Storyboard instead of dynamically
Sample Project
Minimal reproduction project is available here: https://github.com/CH3COOH/Samples/tree/master/SampleSelectSegmentedControl
Feedback Assistant
This issue has been reported via Feedback Assistant: FB21712773
Has anyone else encountered this issue or found alternative workarounds?