xcode (iphone) 中 uitextfield 的高度是多少

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

whats the height of uitextfield in xcode (iphone)

iphonexcodesizeuitextfieldheight

提问by Martin

the square kind... (not rounded)

方形的……(不是圆角的)

Im trying to make a background that fits my texfield and cant seem to find the height (default) anywhere

我正在尝试制作适合我的 texfield 的背景,但似乎无法在任何地方找到高度(默认)

回答by Vladimir

Default height is 31pts (you can see that in IB), but it is fixed only for rounded border style - with all other styles you can set field height to arbitrary value.

默认高度为 31pts(您可以在 IB 中看到),但它仅适用于圆形边框样式 - 对于所有其他样式,您可以将字段高度设置为任意值。

btw, you can find a reference for common UI elements sizes here

顺便说一句,您可以在此处找到常见 UI 元素大小的参考

回答by prewett

[textField sizeThatFits:textField.frame.size].height

If you hard-code 31pts then you will have unsightly visual errors if (when) Apple ever changes the size.

如果您对 31pts 进行硬编码,那么如果(当)Apple 更改大小时,您将出现难看的视觉错误。

回答by David

UITextField is a subclass of UIView so you can send -frameor -boundsto the object.

UITextField 是 UIView 的子类,因此您可以发送-frame或发送-bounds到对象。