[英]I am getting an error in xcode (no available overloads)
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var leftimageview: UIImageView!
@IBOutlet weak var rightimageview: UIImageView!
@IBOutlet weak var leftscorelabel: UIStackView!
@IBOutlet weak var rightscorelabel: UIStackView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarnng() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func resetbutton(_sender: Any) {
print("resetgame")
leftimageview.image = UIImage()
}
}
I am getting this error when I am trying to change the picture displayed when the button in my project is pressed. 当我尝试更改按项目中的按钮时显示的图片时,出现此错误。
You can use a UIImage
like this in one of 2 ways: 您可以通过以下两种方式之一使用
UIImage
:
Using the UIImage(named:)
constructor 使用
UIImage(named:)
构造函数
leftimageview.image = UIImage(named: "rosemary")
The more Swifty way, using an image literal 更快捷的方法,使用图像文字
leftimageview.image = #imageLiteral(resourceName: "rosemary")
You can use a Swift Image Literal in Xcode by starting to type Image Literal
and use the autocomplete and select your image 您可以通过开始键入
Image Literal
并使用自动完成功能并选择您的图像来在Xcode中使用Swift Image Literal
如果您使用的是图片文字,则无需使用UIImage
构造函数,只需执行leftimageview.image = rosemary
,其中rosemary是屏幕快照中的图片文字(与图片预览一起显示,实际上是#imageLiteral(resourceName: "rosemary")
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.