简体   繁体   English

如何使用Xcode 6中的约束来适当调整对象的大小?

[英]How to properly size an object using constraints in Xcode 6?

I'm fairly new to Xcode and I am trying to create a simple app that is universal to support all iPhone screen sizes. 我是Xcode的新手,我正在尝试创建一个通用的简单应用程序,以支持所有iPhone屏幕尺寸。

I'm testing this on an iPhone 5 screen and iPhone 6 screen. 我正在iPhone 5屏幕和iPhone 6屏幕上对此进行测试。

I have the following constraints for the background UIImageView object, which expands to support both screen sizes perfectly. 对于背景UIImageView对象,我具有以下约束,该对象可以扩展为完美地支持两种屏幕尺寸。

在此处输入图片说明

For the View object colored in gray, I set the following constraints: 对于以灰色显示的View对象,我设置了以下约束:

在此处输入图片说明

However, when I tested it on my iPhone 5 and iPhone 6, the View object remains the same size. 但是,当我在iPhone 5和iPhone 6上对其进行测试时,View对象的大小保持不变。 It doesn't resize proportionate to both phone screen sizes because you can see how much space the View object takes as shown: 它不会根据两个电话屏幕的大小调整大小,因为您可以看到View对象占用了多少空间,如下所示:

在此处输入图片说明在此处输入图片说明

Is there any way to fix this? 有没有什么办法解决这一问题?

Thanks! 谢谢!

对于灰度视图,除了CEnterX和CenterY之外,您还需要定义高度约束以及前导空间和0常量的尾随零。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM