【问题标题】: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)


    }

【讨论】:

    猜你喜欢
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 2013-06-06
    • 2015-09-15
    • 1970-01-01
    相关资源
    最近更新 更多