我在 UIImageView 中添加图像,但它不显示
let imageView = UIImageView(frame: CGRect(x: 100, y:20, width: 100, height: 100))
imageView.backgroundColor = UIColor.red
imageView.image = UIImage(named: "sample.jpg")
self.view.addSubview(imageView)
最佳答案
Note: Go to
Assets.xcassets
in your project. then createNew Image Set
with name sample. after that drag and dropsample.jpg
intosample
image set
let imageView = UIImageView(frame: CGRect(x: 100, y:20, width: 100, height: 100))
imageView.backgroundColor = UIColor.red
imageView.image = UIImage(named: "sample") // then use this
self.view.addSubview(imageView)
关于ios - 我在 UIImageView 中添加图像但它不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46487204/