以编程方式更改 UIImageView Xcode Swift 的高度和宽度 [英] Programmatically change the height and width of a UIImageView Xcode Swift

查看:14
本文介绍了以编程方式更改 UIImageView Xcode Swift 的高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,由于某种原因,我正在努力尝试设置我的一个图像视图的高度和宽度.我想设置它,这样高度只占我屏幕的 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 的高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆