Mask for UITextField

1

How do I apply mask to a UITextField ? I found some ways to apply a mask to a UITextField , but it did not seem to me to be a very correct thing to do. It could be an example of a simple phone mask. It can be in Swift or Objective-C.

OBS: a way that does not look like a "gambiarra"

    
asked by anonymous 12.11.2014 / 18:50

2 answers

4

You can use VMaskTextField where you just have to enter a mask to take on the formatting.

For example:

self.maskTextField.mask = @"(##) ####-####";

Other examples:

    
13.11.2014 / 11:42
1

You need to implement the "shouldChangeCharactersInRange" method of TextField.

Inside the method applies the validation of the text that you want whenever there is a change in the text. A great solution I've come to use , allows you to easily apply a reg the text to get that same formatted text.

Analyze the code and apply your needs

    
12.11.2014 / 23:40