只是想知道如何按下“START”按钮,当按下时触发一个功能并且文本变为“STOP”。然后当再次按下时,功能将停止,文本将变回“START”
我已经启动了按钮启动功能。我可以处理更改标题,只是不确定使用什么来使1按钮有2个功能
答案 0 :(得分:2)
添加IBAction方法,如:
- (IBAction)buttonTapped:(id)sender
{
UIButton *btn = (UIbutton *)sender;
NSString *title=btn.titleLabel.text;
if ([title isEqualToString:@"Start"])
{
//Start
}else
{
//Stop
}
}
答案 1 :(得分:1)
请试试这个:
- (IBAction) buttonAction:(id)sender
{
if([[(UIButton *)sender currentTitle]isEqualToString:@"START"])
{
[actionButton setTitle:@"STOP" forState:UIControlStateNormal];
//start the action here and change the button text to STOP
}
else if([[(UIButton *)sender currentTitle]isEqualToString:@"STOP"])
{
[actionButton setTitle:@"START" forState:UIControlStateNormal];
//stop the action here and change the button text to START
}
}
答案 2 :(得分:0)
这里至少有两个选项: