xcode 如何使用界面生成器更改 ipad 的文本字段高度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3728522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change textfield height for an ipad using interface builder?
提问by Fangy
We're using Interface Builder for developing an app for the iPad and we can't figure out how to increase the height of the textfields.
我们正在使用 Interface Builder 为 iPad 开发应用程序,但我们无法弄清楚如何增加文本字段的高度。
When we were using IB to develop an application for osx, you could go to the textfields attributes and under the control section you could set line break to word wrap instead of clip.
当我们使用 IB 为 osx 开发应用程序时,您可以转到 textfields 属性,在控制部分下,您可以将换行符设置为自动换行而不是剪辑。
When we try to use Interface Builder for iPad applications though, it doesn't have the option of changing linebreak style under attributes-->control.
但是,当我们尝试为 iPad 应用程序使用 Interface Builder 时,它没有更改属性->控件下的换行样式的选项。
Is there any way to set the height using Interface Builder or do you have to set that in the code?
有什么方法可以使用 Interface Builder 设置高度,还是必须在代码中设置?
回答by Julian Osorio
It looks like the height of the rounded-style text field is locked in Interface Builder. My solution was to use another of the UITextField
styles in my XIB and then call textField.borderStyle = UITextBorderStyleRoundedRect
in my viewDidLoad
method.
看起来圆形样式文本字段的高度在 Interface Builder 中被锁定。我的解决方案是UITextField
在我的 XIB 中使用另一种样式,然后调用textField.borderStyle = UITextBorderStyleRoundedRect
我的viewDidLoad
方法。
Of course, textField
should be the name of the UITextField IBOutlet
.
当然textField
应该是名字了UITextField IBOutlet
。
回答by Jasarien
iOS UITextField
s are single line only and have a fixed height.
iOS UITextField
s 只有单行并且具有固定的高度。
If you want a multi-line, variable-height text entry field then use UITextView
.
如果您想要多行、可变高度的文本输入字段,请使用UITextView
.
回答by lifeisfoo
1 - Right click on your storyboard/xib file and select "Open as" -> "Source code".
1 - 右键单击您的故事板/xib 文件并选择“打开为”->“源代码”。
2 - Find the xml tag relative to your TextField, e.g.
2 - 查找与您的 TextField 相关的 xml 标签,例如
<textField opaque="NO" clipsSubviews="YES" tag="102" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="6872" borderStyle="roundedRect" placeholder="Password" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Dxw-lR-kq5">
<rect key="frame" x="20" y="337" width="335" height="30"/>
3 - Change the height
value to what you want (e.g. 50)
3 - 将height
值更改为您想要的值(例如 50)
4 - Right click again on you storyboard and select "Open as" -> "Interface builder"
4 - 再次右键单击故事板并选择“打开为”->“界面构建器”
5 - See the result
5 - 查看结果
回答by ZHAO Xudong
there is a wrapping text field,that is what you need.
有一个环绕文本字段,这正是您所需要的。
回答by amar
set the frame of ui textfield object in view did load but it will involve coding
在视图中设置 ui textfield 对象的框架确实加载了,但它会涉及编码
[self.searchText setFrame:CGRectMake(180, 450, 400, 250)];
//in my case the object was called search text...
回答by vishnu_146
You can edit the height of any UITextfield in IB.Just set the constraint in IB.Select the constraint.In the Size Inspector-->Select and Editjust change the constant to your desired value.Press Enter ...Done!!!! (Can't get multiline though)
您可以在 IB 中编辑任何 UITextfield 的高度。只需在 IB 中设置约束。选择约束。在尺寸检查器中-->选择和编辑只需将常量更改为您想要的值。按 Enter ...完成!!! !(虽然无法获得多行)