在 iPhone 中针对不同的屏幕改变 UITextFields 的高度和间距

Vary the UITextFields height and spacing between them for different screens in iPhone

目前,我们正在 iOS 中将网站注册屏幕复制到我们的本机移动应用程序中。到目前为止,我们正在使用 NSLayoutConstraints 以编程方式设置它们之间的约束。我试图通过在 UITextFields 之间提供前导 space 和尾随 space 以及高度约束来在情节提要中进行设置,但我希望根据不同的屏幕设置不同的高度约束,以便它看起来到处都一样,垂直间距也一样。我希望这可以没有编码部分。

https://dribbble.com/shots/6006968-ReCars-Sign-Up-Login

注册屏幕:

与选项一样,您可以使用乘数 1:N 设置文本字段的等高约束。我将在下面添加图片。

But, I do not recommend it. Cause you will have a lot of problems with this solution. In my opinion, a better way to adjust your textfileds on screen is using UIScrollView, but in this way, you will work with the code.

首先,为 textfieldsuperview 添加相同的高度。

其次,设置乘数。

希望对你有帮助

But remember better to make it properly once less than make it in a bad way then remake. :)

有多种方法可以实现这一点。

a> 不要对文本字段使用硬编码高度限制。而是尝试使用相对约束。 Sample Relative Constraint Example . 在示例中,我针对其超级视图对文本字段进行了高度限制。所以根据它的超级视图,它的高度将调整大小。

b> 您还可以探索自适应布局模式。根据大小 class 你可以改变约束条件。