我创建了一个具有操作的UIButton。我已经在编译时设置了它的背景图像(在运行之前,而不是用程序)。我试图在运行时(使用代码)的视图加载函数期间将它的背景图像更改为其他图像。我是swift的新手,在网上找不到这样的东西。这是我正在使用的代码:
import Foundation
import UIKit
import iAd
class gamePlay: UIViewController, ADBannerViewDelegate {
var tempChoice : Int = 0
var counter = 0
@IBAction func b4(sender: UIButton) {
tempChoice = 4
counter = counter + 1
checkAnswer()
}
func checkAnswer(){
print(tempChoice)
}
override func viewDidLoad() {
}
在viewDidLoad函数中,我正在尝试键入
b4.setBackgroundImage.......etc.
但它给了我一个错误,说b4没有设置的背景图像方法或属性。
要访问UIButton,需要将其设置为出口,而不是操作。请注意,您可以在b4函数中更改背景,因为您有可用的UIButton。