[英]Change bar button Item from Play to Pause Swift
我正在創建一個Pomodoro計時器。 我想在按下時將“播放欄”按鈕項更改為“暫停”。 我已經為該按鈕和IBAction創建了IBOutlet。
@IBOutlet weak var playButton: UIBarButtonItem!
@IBAction func startTimer(sender: AnyObject) {
self.playButton = UIBarButtonItem(barButtonSystemItem: .Pause, target: self, action: nil)
}
但這是行不通的。 請幫忙。
嘗試這個,
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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.