I have a text field where the user enters data. It's a phone number field. If the user enters 1234567890
, I want it displayed as (123)-(456)-7890
as the user types. How is this possible?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
Maybe you could use this simple method:
Assuming above method is in
Contact
class, just use the method like this:That would be resulting something like:
Also for format +x (xxx) xxx-xx-xx you can use something like this simple solution:
Thanks so much for the first answer but, i think, that method
-(int)getLength:(NSString*)mobileNumber
is useless. You can try something like below:This felt more clear and handles removing any unwanted characters much more nicely. Formats correctly for 1 (###) ###‑#### or (###) ###‑####
We wrote a custom NSFormatter subclass for phone numbers here: https://github.com/edgecase/PhoneNumberFormatter
You can use it like any other NSFormatter subclass.
C# Xamarin.iOS version of most comprehensive answer on how to do phone formatting in iOS is below