Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISegmentedControl Behaviour

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.

Any ideas?

like image 744
Jasarien Avatar asked Dec 04 '22 16:12

Jasarien


2 Answers

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.

like image 156
Kendall Helmstetter Gelner Avatar answered Dec 24 '22 16:12

Kendall Helmstetter Gelner


This default behavior has been changed in the 3.0 API.

like image 23
mmc Avatar answered Dec 24 '22 15:12

mmc