How can I make a multi lined UISegmentedControl. I need it to have 6 bu开发者_如何学JAVAttons, 3 on each line. How can I do this programatically?
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.
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;
}
}
精彩评论