如何在其他按钮单击上的两个按钮上交换文本

时间:2013-12-18 08:58:41

标签: ios objective-c uibutton

我有三个按钮,btn1标题为'Up',btn2标题为'Down'。 点击第三个按钮btn3后,btn1和btn2的标题变为btn1,标题为'Down',btn2标题为'Up'。如何?

2 个答案:

答案 0 :(得分:1)

试试这个。

-(IBAction)thirdButtonClick:(id)sender
{
   if (!self.isChanged)
   {
     self.isChanged = YES;
     [btn1 setTitle:@"Down" forState:UIControlStateNormal];
     [btn2 setTitle:@"Up" forState:UIControlStateNormal];
   }
   else
   {
     self.isChanged = NO;
     [btn1 setTitle:@"Up" forState:UIControlStateNormal];
     [btn2 setTitle:@"Down" forState:UIControlStateNormal];
   }

}

更新:如果您连续点击第三个按钮,它会相应更改。

答案 1 :(得分:0)

尚未经过测试,但这应该有效。

@interface

Class : Superclass 
{
    Bool flip;
}

@implementation

-(IBAction)thirdButtonClick:(id)sender
{
    [btn1 setTitle:[self titleForBool:flip] forState:UIControlStateNormal];

    flip = !flip;

    [btn2 setTitle:[self titleForBool:flip] forState:UIControlStateNormal];
}

-(NSString*)titleForBool:(BOOL)flip
{
    return flip ? @"Up" : @"Down";
}