CodeGuy
CodeGuy

Reputation: 28907

Multi-Lined UISegmentedControl

How can I make a multi lined UISegmentedControl. I need it to have 6 buttons, 3 on each line. How can I do this programatically?

Upvotes: 3

Views: 2410

Answers (2)

Ali
Ali

Reputation: 4245

Just adding code to @Adam EberBach's answer:

In viewDidLoad

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

Then implement the disableOtherSegmentedControl

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

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

Upvotes: 0

user189804
user189804

Reputation:

You will need to use two of them, using the selectedSegmentIndex property. If, when you get an action from one control, you set the value of the other control's property to -1 it will effectively give you a bank of six buttons in two rows that appear to be linked together as one group.

Upvotes: 6

Related Questions