2015-05-11 57 views

回答

0

您可以通過用戶選擇按鈕 像這樣的屬性:

設置你的按鈕狀態在viewDidLoad

startButton.setTitle("Stop", forState: UIControlState.Selected) 
startButton.setTitle("start", forState: UIControlState.Normal) 

現在,您可以改變按鍵的狀態:

@IBAction func startPauseAction(sender: UIButton) { 
    sender.selected = !sender.selected // action changed the selected 
    if sender.selected { 
    play() 
    } else { 
    pause() 
} 
} 
0

使用的按鈕狀態枚舉

enum ButtonType { 
    case Stop 
    case Play 
    case Pause 
} 
var btnType: ButtonType = .Stop 

@IBOutlet weak var actionBtn: UIButton! 
@IBAction func buttonClicked(sender: UIButton) { 
switch (self.btnType) { 
    case .Stop: 
     self.btnType = .Play 
     // TODO: Change button image/title for current state 
     break 
    case .Play: 
     self.btnType = .Pause 
     // TODO: 
     break 

    case .Pause: 
     // TODO: 
     break 
    } 
} 
+0

謝謝,它幫助我很多 –