【问题标题】:Multi-Lined UISegmentedControl多行 UISegmentedControl
【发布时间】:2013-09-23 17:47:19
【问题描述】:

如何制作多行 UISegmentedControl。我需要它有 6 个按钮,每行 3 个。如何以编程方式执行此操作?

【问题讨论】:

    标签: iphone uisegmentedcontrol


    【解决方案1】:

    您将需要使用其中的两个,使用 selectedSegmentIndex 属性。如果,当您从一个控件获取操作时,将另一个控件的属性值设置为 -1,它将有效地为您提供两行中的一组六个按钮,这些按钮看起来像一组链接在一起。

    【讨论】:

    • 智能且简单的方法。谢谢。我可以补充一点,您可以使用[self.orderOptionsSegmentedControl addTarget:self action:@selector(disableOtherSegmentedControl:) forControlEvents:UIControlEventValueChanged]; 来检测对UISegmentedControl 之一的选择我将在下面的新答案中发布代码,希望有人需要它。
    【解决方案2】:

    只需在@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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-08-02
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      • 2015-03-17
      • 2010-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多