A quick question about the UISegmentedControl class on the iPhone.
Hopefully, some may have noticed how in its default state with 2 segments, the segmented control still will toggle even if the user taps on a segment that is currently selected.
I’ve seen UISegmentedControls in apps that negate that behaviour and don’t toggle when the user presses a selected segment. Namely, Apple’s iTune Store app.
Is there a simple way of preventing this behaviour that I’m overlooking, or do I need to write some logic into the valueChanged?
I’ve been trying to disable currently selected segments and enabling unselected ones, but this seems to change the appearance of the control when I don’t want it do.
- How to programmatically add a UISegmentedControl to a container view
- Change UISegmentedControl selected index or value programmatically
- How do I set the accesibility label for a particular segment of a UISegmentedControl?
- How to change the font size of a single index for UISegmentedControl?
- UISegmentedControl below UINavigationbar in iOS 7
- UISegmentedControl change event not firing in iOS5
4 Solutions Collect From Internet About “UISegmentedControl Behaviour”
Look in the UISegmentedControl.h header file (an easy way is to double click on “UISegmentedControl” in XCode with Command held down).
In there you’ll see a number of items in a _segmentedControlFlags struct. If you make a category on UISegmentedControl, you can manipulate any of those elements – including dontAlwaysToggleForTwoSegments which as you might guess by the name is what you are looking for.
Since this is documented in the API header (though not in the actual documentation) it should be pretty safe to use.
This default behavior has been changed in the 3.0 API.
In 3.0, “_segmentedControlFlags” has been changed to the “momentary” property, which can still be found in the UISegmentedControl.h header file.
Accessing the _segmentedControlFlags via an Category is considered as use of a private API and thus a violation of the License Agreement by Apple, as I had to learn today. Until now, I thought, Categories are a language feature to fix someone elses horrible class design…
- xcode library not found for -lobjc
- Is it possible to get app id from iOS application programmatically?
- PurgeIdleCellConnections causes application to freeze then crash
- iOS NSAttributedString to HTML
- Delete cell from UICollectionView
- Getting this error command /usr/bin/codesign failed with exit code 1 with xcode 9.1?
- Weird issue: UITableViewCell would not detect touch although it's accessory view does
- Animating a bezier curve point
- How to use method swizzle or something on subclasses
- Xcode 6 beta color picker issue
- Restkit Authorization Header disappears
- How to create unique arrays of a given size from an array in Swift?
- How to remove a GeoFire handle for the following observe in Swift?
- Introspection and iteration on an Enum
- UITapGestureRecognizer not working in UIImageView