gpt4 book ai didi

ios - 单击更改 BarButtonItem 图标

转载 作者:搜寻专家 更新时间:2023-11-01 07:26:53 24 4
gpt4 key购买 nike

我正在尝试创建一个计数器。这个想法很简单,你点击“播放”按钮,一旦你点击它就会消失并变成一个“暂停”图标,这将触发不同的 Action 。

我认为为计数器状态设置一个 var 并更改图标(只有一个按钮)就可以解决问题,但我不知道如何为“暂停”或出现在从 Storyboard面板创建下拉菜单时的下拉菜单。

这里是代码:

@IBOutlet weak var playButton: UIBarButtonItem!
var timer = NSTimer()
var currentStatus = "stopped"


@IBAction func playAction(sender: AnyObject) {
if (currentStatus == "stopped"){
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("increaseTimer"), userInfo: nil, repeats: true)
currentStatus = "running"
// change button icon (playButton) to Stop
}
else {
currentStatus = "stopped"
timer.invalidate()
// change button icon (playButton) to Play
}

}

最佳答案

你可以这样设置按钮样式:

//setButton to play
yourBarButtonItem = UIBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Play, target: self, action: "TheMethodThatTheButtonShouldCall"), animated: true)
//setButton to stop
yourBarButtonItem = UIBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Stop, target: self, action: "TheMethodThatTheButtonShouldCall"), animated: true)

关于ios - 单击更改 BarButtonItem 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35489747/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com