0
我想根据我显示的应用程序的哪一部分来更改UIImageView。Swift:基于IF更改UIImageView
在我的视图控制器,这个工程设置图像:
let screenSize = UIScreen.main.bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height
let imageName = "sectionOneBackground"
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image!)
imageView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)
view.addSubview(imageView)
但是,如果我换了图像中的,如果像这样:
var imageName = ""
if (section == "one") {
imageName = "sectionOneBackground"
}
if (section == "two") {
imageName = "sectionTwoBackground"
}
if (section == "three") {
imageName = "sectionThreeBackground"
}
然后,它只是不出现在视图。我完全错过了些什么。没有这个更简单的方法来改变视图的背景吗?
在此先感谢。
你正在使用的ImageView作为实例,创建你的图像视图作为全球 –
能打扰你,并要求张贴,作为一个答案,告诉我怎么样?我是一个noob你看。 – JamesG