whats the height of uitextfield in xcode (iphone)
Asked Answered
H

4

7

the square kind... (not rounded)

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

Hermaphroditism answered 11/4, 2011 at 12:49 Comment(0)
W
15

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.

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

Want answered 11/4, 2011 at 12:51 Comment(2)
@Hermaphroditism :if the answer is correct accept this for other's referenceNannie
@astin, there is a timedelay to accept answers. I tried. Now its doneHermaphroditism
P
1
[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.

Phenylamine answered 28/4, 2013 at 10:36 Comment(0)
C
1

For iOS and iPadOS 14.5. The default height is 34 points for the rounded border style as seen in the Interface Builder.

However, this value can change. To check the size use the following code snippet.

let textField = UITextField()
textField.borderStyle = .roundedRect
print (textField.sizeThatFits(textField.frame.size).height)

Output

34.0
Crosscheck answered 29/6, 2021 at 13:40 Comment(0)
D
0

UITextField is a subclass of UIView so you can send -frame or -bounds to the object.

Desalvo answered 11/4, 2011 at 12:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.