嘿,由于某种原因,我正在努力尝试设置我的一个图像视图的高度和宽度.我想设置它,这样高度只占我屏幕的 20%.我知道要定期设置它,您可以执行以下操作:图像 = (0,0,50,50)
Hey for some reason I am struggling with trying to set the height and width of one of my image views. I want to set it so the height only goes for 20% of my screen. I know to regularly set it you can do things like: image = (0,0,50,50)
但我需要高度不是静态数字.像 image = (0,0, frame.height * 0.2, 50)
But I need the height to not be a static number. Something like image = (0,0, frame.height * 0.2, 50)
有什么建议吗?
Swift 3 中接受的答案:
The accepted answer in Swift 3:
let screenSize: CGRect = UIScreen.main.bounds
image.frame = CGRect(x: 0, y: 0, width: 50, height: screenSize.height * 0.2)
这篇关于以编程方式更改 UIImageView Xcode Swift 的高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!