更改栏按钮项目从播放到暂停斯威夫特

时间:2015-11-13 08:10:19

标签: ios xcode swift

我正在创建一个番茄钟计时器。我想在按下它时将播放栏按钮项目更改为暂停。我已经为这个按钮和IBAction创建了IBOutlet。

@IBOutlet weak var playButton: UIBarButtonItem!

@IBAction func startTimer(sender: AnyObject) {

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

但这不起作用。请帮忙。

1 个答案:

答案 0 :(得分:2)

试试这个,

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
}