iOS故事板AutoLayout并添加约束 [英] iOS storyboard AutoLayout and adding constraint

查看:263
本文介绍了iOS故事板AutoLayout并添加约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更改我的应用以支持3.5显示。目前它支持4显示器。
屏幕布局如下所示。如何在故事板中添加以下约束? (我在故事板中启用了自动布局选项。)

I am making changes to my app to support 3.5″ display. Currently it is supporting 4″ display. The screen layout looks like this. How to add following constraint in storyboard ? (I have enabled auto layout option in storyboard.)


  1. 如何设置button1& button2宽度到超视图宽度的一半?两者都应该在超视图宽度的中间相交。

  1. How to set button1 & button2 width to the half of super view's width ? and both should intersect at the middle of the superview's width.

UIImage#1应放在超视图宽度的中间位置。

UIImage #1 should be placed at the middle of the superview's width.

推荐答案

1:按钮



无法在界面构建器中执行所有操作

您必须在代码中声明 NSLayoutConstraint 出口:

You've got to declare an NSLayoutConstraint outlet in your code :

@property(弱,非原子)IBOutlet NSLayoutConstraint * buttonWidthConstraint;

然后设置:

self.buttonWidthConstraint.constant = self.containerView.frame.size.width / 2;

以下是您在IB中需要做的事情:

Here is what you have to do in IB :


  • 2个按钮必须具有相同的宽度。


  • 对于两个按钮,将它们粘在左右两侧, d底部,并修复它们的高度:

图像视图居中像这样

修复它的宽度,高度和 Y位置

Fix it's width, height, and Y position

希望这会有所帮助。

这篇关于iOS故事板AutoLayout并添加约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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