【发布时间】:2015-02-27 00:59:25
【问题描述】:
在我的应用程序中,我有一个用于启动和停止事件的 UIButton。我目前正在尝试使用以下 IBAction 以编程方式更改 UIButton 的标题及其背景图像:
@IBAction func StartandStop(sender: AnyObject) {
if StartandStop.titleLabel?.text == "Start Flight" {
StartandStop.setTitle("Stop Flight", forState: UIControlState.Normal)
StartandStop.setImage(UIImage(named: "End"), forState: .Normal)
}
else if StartandStop.titleLabel?.text == "Stop Flight" {
StartandStop.setTitle("Start Flight", forState: UIControlState.Normal)
StartandStop.setImage(UIImage(named: "Start"), forState: .Normal)
}
}
我的程序是这样开始的:
但是,当我第一次按下按钮后,它变成了这样:
当我继续按下按钮时,它保持在第二种状态。为什么我的按钮会这样?
【问题讨论】:
标签: swift uibutton interface-builder