IPhone / iOS: Defining Default / Preferred Height UITextField

I am creating a UITextField programmatically (i.e. not in Interface Builder) and I want to know what height value I should use for my frame. Is there an easy way to determine this, or do I need to hard code the value?

+3
source share
2 answers

A UITextFieldcan be as high as possible. There is no “preferred” height if you do not have text inside the text field, in which case you can use the method NSString -sizeWithFont::

CGSize size = [textField.text sizeWithFont:[UIFont systemFontOfSize:12]];
CGRect frame = textField.frame;
frame.size = CGSizeMake(textField.frame.size.width, size.height);
textField.frame = frame;
+5
source

The default interface designer is 31 for rounded text fields.

+16
source

Source: https://habr.com/ru/post/1788142/


All Articles