Programmatically change the height and width of a UIImageView Xcode Swift(以编程方式更改 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 的高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:以编程方式更改 UIImageView Xcode Swift 的高度和宽度
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
