15

Lets say my UISegmentedControl has 8 numbered segments. I would like for the user to be able to turn on 2, 3, or more of them at once. Toggling them. Essentially like a bits in a byte. Is this possible? I believe it is on regular Mac OS X but I can't seem to find a way to do it in the iPhone SDK.

If I have to simulate this by putting buttons into a view, is there any way to do the following:

  1. Round the corners of the view so that it looks like the "bar" style UISegmentedControl?
  2. Use the built-in backgrounds the "bar" style has on the buttons?
  3. Give the buttons a shadow like the whole "bar" style has? (not the text)
dlamblin
  • 43,965
  • 20
  • 101
  • 140

5 Answers5

9

Update: The custom control I mentioned here no longer works under iOS 13.

This is the best custom control I've found that allows multiple segments to be selected concurrently:

https://github.com/yonat/MultiSelectSegmentedControl

This one is a subclass of UISegmentedControl, which is convenient. I've forked it here:

https://github.com/stewartmacdonald/MultiSelectSegmentedControl

and added some code examples to the ReadMe and added a method that allows you to get an NSArray of the titles of all selected segments.

Stewart Macdonald
  • 2,062
  • 24
  • 27
8

This isn't possible using UIKit. I would recommend creating a custom control, or an array of UISwitch controls, representing each of the options in your UISegmentedControl.

pix0r
  • 31,139
  • 18
  • 86
  • 102
2

I think the simplest way is to create your own segmentedcontrol with UIButton.

Marco

Marco
  • 789
  • 1
  • 8
  • 13
  • 3
    One way to do this, which I have done in shipping apps, is to use a UILabel with rounded edges and put rectangular UIButtons inside. This way you can get the rounded edges for the combined control. Enjoy. – Damien Del Russo Feb 13 '12 at 07:03
1

There appears to be a way to do this in XCode now. In the Attributes Inspector, there is a section with Segment, Title, Image, Behavior. The behavior options are "Enabled" and "Selected". You can selecte "Selected" for multiple segments.

Blamdarot
  • 3,317
  • 1
  • 18
  • 15
  • 10
    I don't think this works. In Xcode when I select "Selected" for a segment, the other segments all become unselected. Further the methods for UISegmentedControl include setEnabled:forSegmentAtIndex but not setSelected:forSegmentAtIndex (which would be handy). I'm trying to do the same as the OP and it appears I need to create a custom control. Kind of ironic since the helper buttons at the top Xcode itself are exactly what I'm shooting for (Mac app though). – Damien Del Russo Feb 13 '12 at 07:02
0

I recommend you try https://github.com/tayhalla/THSegmentedControl
it is an actual subclass of UISegmentedControl so it fits nicely with Interface builder and everything.

Ali
  • 18,665
  • 21
  • 103
  • 138