是否可以在一个按钮中有2个标签

时间:2012-06-24 04:51:03

标签: iphone ios5 xcode4.3

这是我的按钮

- (IBAction)startBtn:(id)sender {

}

我的问题是,当我单击带有START标签的startBtn时,该过程开始但标签更改为CANCEL以取消该过程。我不想制作START和CANCEL的2个按钮,我只想将它们放在一个startBtn按钮中。

有任何帮助吗? 感谢您与我分享您的知识。

2 个答案:

答案 0 :(得分:1)

// set titles in viewDidLoad Method or in interface builder
[button setTitle:@"Start" forState:UIControlStateNormal];
[button setTitle:@"Cancel" forState:UIControlStateSelected];


- (IBAction)startBtn:(id)sender {
    UIButton *button = sender;
    button.selected = !button.selected;

    if (button.slected) {
       // start process
    }
    else {
      // stop process
   }

}

答案 1 :(得分:0)

- (IBAction)startBtn:(id)sender {
     [button setTitle:@"Cancel" forState:UIControlStateNormal];
}

- (IBAction)cancelBtn:(id)sender {
     [button setTitle:@"Start" forState:UIControlStateNormal];
}