【发布时间】:2013-09-23 17:47:19
【问题描述】:
如何制作多行 UISegmentedControl。我需要它有 6 个按钮,每行 3 个。如何以编程方式执行此操作?
【问题讨论】:
如何制作多行 UISegmentedControl。我需要它有 6 个按钮,每行 3 个。如何以编程方式执行此操作?
【问题讨论】:
您将需要使用其中的两个,使用 selectedSegmentIndex 属性。如果,当您从一个控件获取操作时,将另一个控件的属性值设置为 -1,它将有效地为您提供两行中的一组六个按钮,这些按钮看起来像一组链接在一起。
【讨论】:
[self.orderOptionsSegmentedControl addTarget:self action:@selector(disableOtherSegmentedControl:) forControlEvents:UIControlEventValueChanged]; 来检测对UISegmentedControl 之一的选择我将在下面的新答案中发布代码,希望有人需要它。
只需在@Adam EberBach 的答案中添加代码:
在viewDidLoad
[self.orderOptionsSegmentedControl1 addTarget:self action:@selector(disableOtherSegmentedControl:) forControlEvents:UIControlEventValueChanged];
[self.orderOptionsSegmentedControl2 addTarget:self action:@selector(disableOtherSegmentedControl:) forControlEvents:UIControlEventValueChanged];
然后实现disableOtherSegmentedControl
- (void) disableOtherSegmentedControl:(id)sender
{
if (sender == self.orderOptionsSegmentedControl1)
{
self.orderOptionsSegmentedControl2.selectedSegmentIndex = -1;
}
else if (sender == self.orderOptionsSegmentedControl2)
{
self.orderOptionsSegmentedControl1.selectedSegmentIndex = -1;
}
}
【讨论】: