objective-c 如何在大小检查器中设置文本字段的高度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/716950/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 21:21:08  来源:igfitidea点击:

How to set height for a textfield in size inspector

iphoneobjective-c

提问by ksnr

i created a UITextField of type rounded textfield, using Interface Builder,so in order to set the Height of a textfield its window was disabled(not to set any height manually) in SizeInspector.so if we want to set height manually,what procedure should we follow.

我使用界面生成器创建了一个圆形文本字段类型的 UITextField,因此为了设置文本字段的高度,它的窗口在 SizeInspector.so 中被禁用(不手动设置任何高度)。所以如果我们想手动设置高度,应该执行什么程序我们跟随。

One thing i would like to mention is ,we can do that in coding part,but what i would like to know is ,how can we acheive that in interfacebuilder.

我想提到的一件事是,我们可以在编码部分做到这一点,但我想知道的是,我们如何在界面构建器中实现这一点。

Answers from you were always appreciated.

您的回答总是受到赞赏。

回答by Adam Waite

Change the border style, like this:

更改边框样式,如下所示:

screen shot

截屏

回答by Alexandre L Telles

Unfortunately you can't set the Height of a UITextField using Interface Builder. You will have to set it programatically and be sure it doesn't break any rules from iPhone Human Interface Guidelines

不幸的是,您无法使用 Interface Builder 设置 UITextField 的高度。您必须以编程方式设置它,并确保它不会违反iPhone 人机界面指南中的任何规则

回答by sachy

You can change the height of UITextFieldby editing the .xib file. Just open it using Textedit or Dashcode and search for the IBUITextField. Edit to NSFrameparameter to whatever size u want.

您可以UITextField通过编辑 .xib 文件来更改 的高度。只需使用 Textedit 或 Dashcode 打开它并搜索IBUITextField. 将NSFrame参数编辑为您想要的任何大小。

回答by nessalabs

increase the size of the font and the box's height will increase

增加字体的大小,框的高度会增加

回答by Ville Laurikari

Change the Border Style property of the text field to something other than the rounded rectangle. After that you can freely set the height of the box.

将文本字段的边框样式属性更改为圆角矩形以外的内容。之后,您可以自由设置框的高度。

回答by Mohd Iftekhar Qurashi

Right click on .xib file and click on "Open As"-> "Source Code". Then search for UITextField's NSFrame. Change the height as you want.

右键单击 .xib 文件,然后单击“打开为”->“源代码”。然后搜索 UITextField 的 NSFrame。根据需要更改高度。

回答by Demilitarized Zone

Successful solution with my condition: After trying all above ways, I could not change the height of UITextField. Finally, I found out that I put UITextFieldin stack view (or it was affected by some constraints).

我的情况成功的解决方案:尝试上述所有方法后,我无法更改UITextField. 最后,我发现我放入UITextField了堆栈视图(或者它受到了一些约束)。

So, I added Height Constraintfor UITextFieldthen put my expected height in Constantof Constraint. And it works. Specially, it works for all Border-style (None, Line, Bezel, RoundedRect). No code is needed.

所以,我添加Height ConstraintUITextField然后把我的预期高度放在Constant约束中。它有效。特别是,它适用于所有边框样式(无、线条、边框、圆角矩形)。不需要代码。

回答by Ahmet Karaku?

I resolved textfield (with rounded rect) height problem. You must define height constraint for your textfield object.

我解决了文本字段(带有圆形矩形)高度问题。您必须为文本字段对象定义高度约束。

Define height constraint for Textfield.

为 Textfield 定义高度约束。

回答by Anju Chowdary

We can change height of Text Field with any type of border style other than rounded rectangle by simply dragging. But for the Rounded Rectangle Text fields it is not possible...of course we can change height using some code.

我们可以通过简单的拖动来更改带有圆角矩形以外的任何类型边框样式的文本字段的高度。但是对于圆角矩形文本字段这是不可能的......当然我们可以使用一些代码更改高度。

And here I found a simple way. It worked for me

在这里我找到了一个简单的方法。它对我有用

  1. Select the text field and at the below right corner we can see the pins option..

  2. There select the height constrain it is 30 pre-defined...

  3. select that height and you can see "Add 1 Constraint" is enabled.
  4. Click on that..therefore we have added height constraint for that text field.
  5. Now go to the size inspector. There find the Height constraint in "Constraints"...which is above the "Content Hugging Priority"
  6. You can edit the height there...give whatever value you want to give. Now see the textfield it is changed to its height which you have given.
  1. 选择文本字段,在右下角我们可以看到 pin 选项..

  2. 那里选择高度约束它是 30 预定义...

  3. 选择该高度,您可以看到“添加 1 个约束”已启用。
  4. 单击那个..因此我们为该文本字段添加了高度约束。
  5. 现在去尺寸检查器。在“约束”中找到高度约束......高于“内容拥抱优先级”
  6. 您可以在那里编辑高度...提供您想要提供的任何值。现在看到它更改为您提供的高度的文本字段。

It worked for me :) Can use this scenario for UISwitch, Segment, etc..

它对我有用:) 可以将此场景用于 UISwitch、Segment 等。

回答by JerryZhou

As @peterdoesco.de said, Just add an Height constraint, and change it's value, this can works fine.

正如@peterdoesco.de 所说,只需添加一个高度约束,并更改其值,就可以正常工作。