UITextField

A text field has many of the same properties as a label, but a text field can’t contain multiple lines. So it has a text, font, textColor, and textAlignment. It also has adjustsFontSizeToFitWidth and minimumFontSize properties, although these don’t work exactly like a label; a text field won’t allow its font size to shrink automatically as small as a label will. If the user enters text that is too long for the width of the field, the text moves (scrolls horizontally) to show the insertion point, but when the field is no longer being edited, text that is too long is displayed with an ellipsis at the end.

A text field also has a placeholder property, which is the text that appears faded within the text field when it has no text; the idea is that you can use this to suggest to the user what the text field is for. If its clearsOnBeginEditing property is YES, the text field automatically deletes its existing text when the user begins editing within it.

A text field’s border drawing is determined by its borderStyle property. Your options are:

UITextBorderStyleNone
No border.
UITextBorderStyleLine
A plain rectangle.
UITextBorderStyleBezel
A slightly bezeled rectangle: the top and left sides have a very slight, thin shadow.
UITextBorderStyleRoundedRect
A rounded rectangle; the top and left sides have a stronger shadow, so that the text appears markedly recessed behind the border.

A text field can have a background color (because it is a UIView) or a background image ( ...

Get Programming iOS 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.