0

这是我的按钮

- (IBAction)startBtn:(id)sender {

}

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

有什么帮助吗?谢谢你为我分享你的知识。

4

2 回答 2

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
   }

}
于 2012-06-24T05:50:39.867 回答
0
- (IBAction)startBtn:(id)sender {
     [button setTitle:@"Cancel" forState:UIControlStateNormal];
}

- (IBAction)cancelBtn:(id)sender {
     [button setTitle:@"Start" forState:UIControlStateNormal];
}
于 2012-06-24T04:57:35.980 回答