开发者

Switch with 3 options in iOS

开发者 https://www.devze.com 2023-03-09 02:26 出处:网络
The default sw开发者_开发问答itch 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?UISegmentedControl?If you are using Interface

The default sw开发者_开发问答itch 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?


UISegmentedControl?


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];


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消