除了 UITextField 之外,如何为 UIImageView 提供约束?

How to give the Constraints for the UIImageView besides the UITextField?

我有一个登录页面,除了 UITextField 之外,我们还需要在其中放置 UIImage(比如手机号码)。所以我设置的约束是这样的:

手机号码

UIImage:通向容器,宽高,水平间距通向UITextField

UITextField:尾部到容器,到个人资料图片的 UIImageView 的垂直间距、高度和宽度。

同样对于密码

UIImage:通向容器,宽高,水平间距通向UITextField

UITextField:尾部到容器,到 UITextField(手机号码)的垂直间距,高度和宽度。

但仍然无法满足所有屏幕的 Iphone 限制条件。

听起来你只有一件事错了...

不要在您的 UITextFields 上设置宽度限制。

Horizo​​ntal Spacing from image to textfield 设置文本字段的 "left edge",文本字段的 Trailing to the Container 约束设置文本字段的 "right edge"。

因此,在不同宽度的屏幕上,文本字段将拉伸以填充 space。