SINUITextFieldPhoneNumberFormatter Class Reference
Inherits from | NSObject |
---|---|
Declared in | SINUITextFieldPhoneNumberFormatter.h |
Overview
SINUITextFieldPhoneNumberFormatter is a helper to perform As-You-Type-Formatting on a UITextField. The formatter performs formatting based on the region country code given at initialization.
Example usage:
// Assuming the following properties:
@property UITextField* textField;
@property SINUITextFieldPhoneNumberFormatter* formatter;
self.formatter = [[SINUITextFieldPhoneNumberFormatter alloc] init];
self.formatter.textField = self.textField;
self.textField.placeholder = [self.formatter exampleNumberWithFormat:
SINPhoneNumberFormatNational];
onTextFieldTextDidChange
onTextFieldTextDidChange is a block that is invoked when the text value of the observed UITextField changes. This callback handles both events from UITextFieldTextDidChangeNotification and KVO-events for the UITextField.text property.
@property (nonatomic, copy, readwrite, nullable) void ( ^ ) ( UITextField *) onTextFieldTextDidChange
Discussion
It can be used to implement additional hooks like indicating to the user whether the current input is a possibly valid phone number, e.g. with [SINPhoneNumberUtil isPossibleNumber:error:].
Declared In
SINUITextFieldPhoneNumberFormatter.h
– init
Default initialization. Equivalent to initializing with SINPhoneNumberUtil() and [SINDeviceRegion currentCountryCode].
- (instancetype)init
Declared In
SINUITextFieldPhoneNumberFormatter.h
– initWithCountryCode:
ISO 3166-1 two-letter country code that indicates the country/region where the phone number is being entered.
- (instancetype)initWithCountryCode:(NSString *)isoCountryCode
Parameters
isoCountryCode |
ISO 3166-1 two-letter country code that indicates the country/region where the phone number is being entered. |
---|
Declared In
SINUITextFieldPhoneNumberFormatter.h
– initWithPhoneNumberUtil:countryCode:
Designated initializer.
- (instancetype)initWithPhoneNumberUtil:(id<SINPhoneNumberUtil>)phoneNumberUtil countryCode:(NSString *)isoCountryCode
Parameters
phoneNumberUtil |
instance of utility class that will be used for phone number parsing and formatting. |
---|---|
isoCountryCode |
ISO 3166-1 two-letter country code that indicates the country/region where the phone number is being entered. |
Declared In
SINUITextFieldPhoneNumberFormatter.h
– exampleNumberWithFormat:
Get a an example phone number formatted according to given format.
- (NSString *)exampleNumberWithFormat:(SINPhoneNumberFormat)format
Return Value
a formatted phone number string. Will return an empty string if no example phone number is available for the given region country code.
Discussion
The returned string can be used as placeholder text for a UITextField.
Declared In
SINUITextFieldPhoneNumberFormatter.h