import UIKit
class ViewController: UIViewController {
let canoaimageview: UIImageView = {
let imageview = UIImageView(image: canoa) //ERROR Use of unresolved identifier 'canoa'
imageview.translatesAutoresizingMaskIntoConstraints = false
return imageview
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(canoaimageview)
setupLayout()
}
private func setupLayout() {
canoaimageview.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
canoaimageview.topAnchor.constraint(equalTo: view.topAnchor, constant: 100).isActive = true
canoaimageview.widthAnchor.constraint(equalToConstant: 150).isActive = true
canoaimageview.heightAnchor.constraint(equalToConstant: 150).isActive = true
}
}
//an attached image is included showing the error and assets folder
You need to make an UIImage first to assign it to imageView like this
let canoaimageview: UIImageView = {
let imageview = UIImageView(image: UIImage(named: "canoa")) //ERROR Use of unresolved identifier 'canoa'
imageview.contentMode = .scaleAspectFit
imageview.translatesAutoresizingMaskIntoConstraints = false
return imageview
}()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.