在故事板上使用约束多重UITextField

时间:2016-04-22 11:15:32

标签: ios iphone autolayout uitextfield constraints

我正在尝试习惯AutoLayout和Constraints,

我面临的挑战是,我需要有六个文本字段相互跟随。

我试图做一些事情,但最后的观点如下;

我错过了什么?enter image description here

1 个答案:

答案 0 :(得分:0)

正如我在评论中提到的,你总是可以使用StackView:)

以下是如何做到这一点:)

首先向视图控制器添加六个文本字段:)enter image description here

尚未向任何文本字段添加约束:)

现在选择所有textfields和stackView给他们:)

enter image description here

添加堆栈后,它看起来像:)

现在选择textField中的任何一个并添加宽度约束:) 然后选择所有文本文件并选择Equal Width约束:)

enter image description here

如果要在所有文本字段之间添加相等的间距:)删除文本字段上的宽度约束:)选择stackView enter image description here

最后你必须将约束添加到stackView本身:)多数民众赞成:) enter image description here

最终输出看起来像这样:)

enter image description here

希望我的冗长答案能帮到你:D