Is there a simple way to spawn an empty UIImage view programmatically without having to have an the code to add an image into the actual image view
You only need to create the imageView. And you can set a background colors to be sure there is the image view.
let imageview: UIImageView = {
let img = UIImageView()
img.backgroundColor = .red
img.translateAutoresizingMaskIntoConstraints = false
return img
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubView(imageView)
imageView.widthAnchor.constraint(equalToConstant: 100).isActive = true
imageView.heightAnchor.constraint(equalToConstant: 100).isActive = true
}
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.