gpt4 book ai didi

ios - 我在 UIImageView 中添加图像但它不显示

转载 作者:行者123 更新时间:2023-11-30 12:07:43 28 4
gpt4 key购买 nike

我在 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 create New Image Set with name sample. after that drag and drop sample.jpg into sample 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com