简体   繁体   中英

Change bar button Item from Play to Pause Swift

I'm creating a Pomodoro Timer. And I want change the Play bar button item to Pause when I press on it. I've already created the IBOutlet for this button and IBAction.

@IBOutlet weak var playButton: UIBarButtonItem!

@IBAction func startTimer(sender: AnyObject) {

    self.playButton = UIBarButtonItem(barButtonSystemItem: .Pause, target: self, action: nil)
}

But this doesn't work. Please help.

try this,

func play() {

    var pauseButton = UIBarButtonItem(barButtonSystemItem: .Pause, target: self, action: "pause") //Use a selector
    navigationItem.rightBarButtonItem = pauseButton
    //other stuff
}

func pause() {
    var playButton = UIBarButtonItem(barButtonSystemItem: .Play, target: self, action: "play") //Use a selector
    navigationItem.rightBarButtonItem = playButton
    //other stuff
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM