Jim
Jim

Reputation: 259

Switch with 3 options in iOS

The default switch element only has two options on and off. I need one with 3 options, does anyone know where I can find a library for that?

Upvotes: 4

Views: 5002

Answers (4)

I would say UISegmentedControl as well, but if for some reason you must have that sliding action then a UISlider would work - you can track the changes in code and "snap" to one of three settings as the user moves the control past a breakover point. That would probably feel a lot like the three-way switch you are looking for while not being too weird.

Upvotes: 2

Radix
Radix

Reputation: 3657

Their is no such library which has a switch with three options and if you want the switch with three options then in that case create a custom view for that by inheriting the UISwitch class.

Also if you find it hard to make the custom view then in that case you may use the segment control and implement it with three segments, here's a tutorial on segment controls.

Upvotes: 0

dbslone
dbslone

Reputation: 2034

If you are using Interface Builder you can change the number of segments to 3 and then double click on each segment to change the value.

If adding by code you can use the following:

UISegmentedControl *myControl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(170, 5, 125, 35)];
[myControl insertSegmentWithTitle: @"Easy" atIndex: 0 animated: NO ];
[myControl insertSegmentWithTitle: @"Hard" atIndex: 1 animated: NO ];
myControl.selectedSegmentIndex = 0;
[myControl addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventValueChanged];

Upvotes: 6

user745098
user745098

Reputation:

UISegmentedControl?

Upvotes: 10

Related Questions