UITextField: text property
The text property is the entire content of the field.
Value
A string.
- Readable and writable.
- The default is the empty string
''. When there is no content it is'', notnull, so you can readlengthdirectly. - A written value that is not a string is converted to a string. Writing
nullorundefinedgives''. - Writing it replaces the whole content of the field.
inputfires when the user's input changes the content. Writingtextfrom code fires neitherinputnorbeforeinput. Thatinputdoes not fire is not verified in the simulator. To make a change from code fireinputtoo, useinsertText().- If
attributedTextwas written and thentextis written, the text ofattributedTextchanges to match. Whether the original styles are kept is not verified in the simulator.
Examples
js
const field = new UITextField();
field.text = 'Jo';
console.log(field.text.length);Result: Prints 2. The field shows "Jo".
Corresponding iOS API
UITextField.text. nil reads as ''.
See also
insertText(): changing the content the way the user typeshasText