第 1 步:创建布尔变量
var isPlaying:Bool = false
Run Code Online (Sandbox Code Playgroud)
步骤 2:使用此 IBAction 方法连接您的按钮:
@IBAction func btnStartStop(sender: UIButton) {
if isPlaying{
isPlaying = false
sender.setTitle("Pause", forState: UIControlState.Normal)
sender.setImage(pauseImage, forState: .Normal)
//Pause Stopwatch
}
else{
isPlaying = true
sender.setTitle("Play", forState: UIControlState.Normal)
sender.setImage(playImage, forState: .Normal)
//Play Stopwatch
}
}
Run Code Online (Sandbox Code Playgroud)