Switch with 3 options in iOS

By default, the switch element only turns on and off two parameters. I need one of 3 options, does anyone know where I can find a library for this?

+4
source share
4 answers

If you use Interface Builder, you can change the number of segments by 3, and then double-click on each segment to change the value.

When adding 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]; 
+6
source
+10
source

I would say UISegmentedControl , but if for some reason you need to have this sliding action, then UISlider will work - you can track code changes and "bind" to one of three parameters as the user moves the control through the pivot point. It will probably be like the three-way switch you are looking for, but not too weird.

+2
source

They don’t have a library that has a switch with three parameters, and if you want the switch to have three options, then in this case create a custom view for it, inheriting the UISwitch class.

Also, if it’s difficult for you to make a custom view, then in this case you can use the segment control and implement it with three segments, here is a tutorial for managing segments.

0
source

All Articles