Layered UISegmentedControl

How to create a multi-level UISegmentedControl. I need it to have 6 buttons, 3 on each line. How can I do this programmatically?

+3
source share
2 answers

You will need to use two of them using the property selectedSegmentIndex. If, when you receive an action from one control, you set the value of another control property to -1, it will effectively give you a bank of six buttons in two lines that appear to be connected to each other as one group.

+6
source

Just add the code to @Adam EberBach's answer:

AT viewDidLoad

[self.orderOptionsSegmentedControl1 addTarget:self action:@selector(disableOtherSegmentedControl:) forControlEvents:UIControlEventValueChanged];
[self.orderOptionsSegmentedControl2 addTarget:self action:@selector(disableOtherSegmentedControl:) forControlEvents:UIControlEventValueChanged];

Then we realize disableOtherSegmentedControl

- (void) disableOtherSegmentedControl:(id)sender
{
    if (sender == self.orderOptionsSegmentedControl1)
    {
        self.orderOptionsSegmentedControl2.selectedSegmentIndex = -1;
    }

    else if (sender == self.orderOptionsSegmentedControl2)
    {
        self.orderOptionsSegmentedControl1.selectedSegmentIndex = -1;
    }
}
+1
source

Source: https://habr.com/ru/post/1790128/


All Articles