【问题标题】:Change title of UIButtons based on index, just like UISegmentedControl根据索引更改 UIButtons 的标题,就像 UISegmentedControl
【发布时间】:2015-05-23 07:30:30
【问题描述】:

当我使用segmentedControl 时,我会根据未知的indices(运行前)执行以下操作来设置标题:

[self.segment setTitle:@"this Title" forSegmentAtIndex:next];
[self.segment setTitle:@"another Title" forSegmentAtIndex:after];

我正在尝试使用UIButtons 复制UISegmentedControl。如何使用UIButtons实现上述代码?

我想将buttons 添加到array,但如果这样做,我将无法通过array index 设置标题。任何建议

【问题讨论】:

    标签: ios objective-c uibutton nsarray uisegmentedcontrol


    【解决方案1】:

    当然,您可以将按钮放在数组中,并且使用数组索引必须像您对分段控件所做的那样。

    NSArray *buttons = ... // your array of buttons
    [buttons[next] setTitle:@"this Title" forState:UIControlStateNormal];
    [buttons[after] setTitle:@"another Title"] forState:UIControlStateNormal];
    

    【讨论】:

      【解决方案2】:

      [button setTitle:@"After" forState:UIControlStateNormal];

      [button setTitle:@"Next" forState:UIControlStateNormal];

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-17
        • 1970-01-01
        相关资源
        最近更新 更多