微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在我的案例 UILabel 和 UITextField 中,如何减少 UI 组件之间的宽度

如何解决在我的案例 UILabel 和 UITextField 中,如何减少 UI 组件之间的宽度

我有一个 UILabel(空格)UITextField。 UITextField 是右对齐的,每当用户输入 UITextField 字段时,应减少 UILabel 之间的水平空间。下面一行来自 UIView,它具有与 UITextField 相同的宽度。如何在不重叠 UILabel 的情况下通过适当的约束实现这一点?

解决方法

所以你想要这样的东西?

3 characters in text field,small width

Many characters in text field,larger width

以下是您需要的约束条件:

Diagram showing constraints needed

结果:

Text field and green view expanding as more text is entered

Demo Repo

编辑:防止文本字段覆盖标签

您需要:

  1. 在标签和文本字段之间添加 greater than or equal to 约束
  2. 将标签的 horizontal compression resistance 设置为 751 而不是 750

Add extra constraints

我制作了这个 video 以便您可以跟随。

结果:

Text field expands as text is entered,but stops as soon as it hits the label

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。