如何使用一个瞬时按钮创建UISegmentedControl?

时间:2013-09-30 15:02:29

标签: ios uisegmentedcontrol

我希望UISegmentedControl中包含许多可选选项,但还包含一个无法选择的Info按钮。 UISegmentedControl类引用讨论了使用一个瞬时公开按钮,暗示它可能,但没有其他任何东西或在头文件中解释如何做这样的事情。

那我怎么能这样做呢?

1 个答案:

答案 0 :(得分:1)

经过多次实验,我发现在所选索引上保留一个阴影变量让我这样做。在以下代码中,info按钮为1,其他按钮可选。在viewDidLoad中设置初始值(或向控件询问其选定的索引)。然后使用以下代码执行操作方法:

- (IBAction)segmentAction:(UISegmentedControl *)sender
{
    NSUInteger idx = [sender selectedSegmentIndex];
    switch(idx) {
    case 1:  // momentary button
        sender.selectedSegmentIndex = selectedIndex;
        break;
    default:
        selectedIndex = idx;
        // other stuff
        break;
    }
    ...

基本上您需要做的就是重置所选索引。仅使用iOS7测试。