Add number formatter to field

How do I add a number formatter to a field?

I know I can use the text field with number formatter already attached...

and I can option drag a copy from another field with it applied.

xcode 9.2

Replies

Not sure I fully understood your question.

I know I can use the text field with number formatter already attached...

What do you mean here ?



You have to do the formatting in the delegate methods of the UITextField.


The

UITextField
class does not provide built-in support for formatting its string using an
Formatter
object, but you can use the text field’s delegate to format the content yourself. To do so, use the text field’s delegate methods to validate text and to format it appropriately. For example, use the
textField(_:shouldChangeCharactersIn:replacementString:)
method to validate and format text while the user is typing. For information about how to use formatter objects, see Data Formatting Guide.


You will find details here:

https://developer.apple.com/documentation/uikit/uitextfield

Drag a formatter object from the object library to the field.