[英]Keeping aspect ratio and autolayout for different devices
I have labels and toolbars on the top and bottom of the screen with height constraints. 我在屏幕的顶部和底部具有高度限制的标签和工具栏。 And I got UIImage between toolbars.
我在工具栏之间得到了UIImage。 So toolbars and labels are keeping same height for different devices while space between toolbars is changeable.
因此,工具栏和标签对于不同的设备保持相同的高度,而工具栏之间的空间是可变的。
My goal is to keep aspect ratio 1:1 for devices from SE to IPad and to center UIImage between toolbars by stretching it until it reach superview margins on sides or toolbars on top and bottom. 我的目标是使SE到IPad的设备的宽高比保持1:1,并通过将UIImage拉伸到侧面或顶部和底部的工具栏上的超级视图边缘,将UIImage居中。 I was tried different approaches but the best thing I could get is on below screenshot.
我尝试了不同的方法,但最好的方法是在屏幕截图下方。
It's keeping aspect ratio but I can't figure out how to keep it centered between toolbars. 它保持了宽高比,但是我不知道如何使它在工具栏之间居中。
Constraints for UIImage: UIImage的约束:
Since I'm working on iOS 8 supported app I didn't use UIStackView and try to find a solution with constraints only. 由于我正在使用受iOS 8支持的应用程序,因此我没有使用UIStackView而是尝试查找仅具有约束的解决方案。
You need to do following things : 您需要执行以下操作:
Add a new view (says, centerView) in between the yellow and green view and give it clear color and give below constraints 在黄色和绿色视图之间添加一个新视图(例如,centerView),并为其赋予清晰的颜色并提供以下约束
Now in centerView add ImageView which have Apple logo and give below constraints. 现在在centerView中添加具有Apple徽标的ImageView并给出以下约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.