【问题标题】:How do I change image of button when pressed xcode 7 / Swift 2? [duplicate]按下 xcode 7 / Swift 2 时如何更改按钮的图像? [复制]
【发布时间】:2015-07-30 07:26:22
【问题描述】:
到目前为止,我有这个,不知道下一步该做什么。我目前在我的视图控制器中有一个带有图像(播放图像)的按钮,并希望在单击时将其更改为暂停图像。
import UIKit
import AVFoundation
class VesuviusViewController: UIViewController {
@IBOutlet weak var PausePlay: UIButton!
@IBAction func playPressed(sender: AnyObject) {
VesSet()
}
【问题讨论】:
标签:
ios
xcode
swift
swift2
xcode7
【解决方案1】:
尝试将其添加到您的按钮单击操作中
sender.setImage(UIImage(named: "play.png")!, forState: .Normal)
【解决方案2】:
@IBAction func playPressed(sender: AnyObject) {
VesSet()
sender.selected = !_btnCheckbox.selected;//put the appropriate login of swift to do that
//checkbox
sender.setImage(UIImage(named: "play.png")!, forState: .Normal)
sender.setImage(UIImage(named: "pause.png")!, forState: .selected)
}