如何在 Swift 中制作全宽 UITextField [英] How to make a full-width UITextField in Swift

查看:34
本文介绍了如何在 Swift 中制作全宽 UITextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Swift 非常陌生,就像一个星期新人,我想想出一个 100% 宽度的 UITextField.预期结果是文本字段应为屏幕宽度的 100%.

I'm very new to Swift, like one week new and I'd like to come up with a 100% width UITextField. The expected result is that the text field should be 100% of the screen's width.

这是我为 iPhone 5 显示器所做的,它有一个 320px 垂直居中的 TextField.

This is what I've done for iPhone 5 displays having a 320px vertically centered TextField.

这看起来符合预期,但是当我使用 iPhone 6 时,会发生这种情况:

That looks as expected, but when I'm going on iPhone 6, this happens:

如何使屏幕宽度达到 100%?因为我只能在尺寸检查器中看到固定宽度的输入.

How is it possible to make this 100% of the screen's width? As I can only see fixed width inputs in size inspector.

推荐答案

你不应该指定文本字段的宽度,而是指定其父视图的前后空格:

You should not specify the width but the leading and trailing space of the textfield to its superview:

  • 选择要对齐的UITextField
  • 点击Pin 图标
  • 取消选中约束到边距"
  • 将前导设置为 0
  • 将尾数设为 0

这将导致 TextField 在每个屏幕上跨越整个宽度:

which will result in the TextField to span the entire width on every screen:

请注意,有时您必须指定要相对于设置空间的视图:

Note that you sometimes have to specify the view you want to set the space relative to:

这篇关于如何在 Swift 中制作全宽 UITextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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