Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I enable multiple segments of a UISegmentedControl to be selected?

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)
like image 790
dlamblin Avatar asked Jun 22 '09 21:06

dlamblin


People also ask

What are segmented controls?

A segmented control is a linear set of two or more segments, each of which functions as a button. Within a segmented control, all segments are usually equal in width. Like buttons, segments can contain text or images. Segments can also have text labels beneath them (or beneath the control as a whole).

What is segmented control in Xcode?

January 23, 2019. A segmented control is a set of two or more segments, each of which functions as a mutually exclusive button. Within the control, all segments are equal in width.

What is segment control in Swift?

Segment control can be defined as the horizontal control, which controls multiple segments where a discrete button controls each segment. A segment control can be used to display multiple views within a single view controller, where each view can be displayed by using a discrete button.


2 Answers

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.

like image 193
Stewart Macdonald Avatar answered Oct 18 '22 00:10

Stewart Macdonald


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.

like image 8
pix0r Avatar answered Oct 17 '22 23:10

pix0r