我用过 ScrollView 。在 Scrollview 上,我有一个 UIView,我可以在其中将图像设置为背景。但问题是图像高度没有与 UIView 高度合并。滚动底部时会显示。我想添加带有整个 UIView 的图像。 这是我的图像屏幕截图
这是我的代码
let backgroundImage = UIImageView(frame: UIScreen.main.bounds)
backgroundImage.clipsToBounds = true
backgroundImage.image = UIImage(named: "background_image")
backgroundImage.contentMode = .scaleToFill
self.my_view_2.insertSubview(backgroundImage, at:0)
请帮助我 谢谢
最佳答案
UIImageView
的高度与屏幕尺寸相同,如果您的 View 大于屏幕尺寸,则白色 View 将保留在底部。
let backgroundImage = UIImageView(frame: UIScreen.main.bounds)
使用 ScrollView 更新backgroundImage
的框架,如下:
let backgroundImage = UIImageView(frame: self.my_view_2.bounds)
backgroundImage.autoresizingMask = [.flexibleHeight, .flexibleWidth] // In case if your my_view_2 frames increases
self.my_view_2.insertSubview(backgroundImage, at: 0)
关于ios - 如何在swift 4中的 subview 中填充背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49870579/