From 611d131bd107155c1f55a5604c4ae767330ea5e6 Mon Sep 17 00:00:00 2001 From: Khoren Markosyan Date: Sun, 28 Jul 2019 15:26:32 +0400 Subject: [PATCH] Allow to set example phone number type --- Sources/FPNTextField.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/FPNTextField.swift b/Sources/FPNTextField.swift index 4750c559..6335e3ee 100644 --- a/Sources/FPNTextField.swift +++ b/Sources/FPNTextField.swift @@ -37,6 +37,7 @@ open class FPNTextField: UITextField, FPNCountryPickerDelegate, FPNDelegate { private lazy var phoneUtil: NBPhoneNumberUtil = NBPhoneNumberUtil() private var nbPhoneNumber: NBPhoneNumber? private var formatter: NBAsYouTypeFormatter? + private var exampleNumberType: NBEPhoneNumberType = .MOBILE public var flagButton: UIButton = UIButton() @@ -283,6 +284,13 @@ open class FPNTextField: UITextField, FPNCountryPickerDelegate, FPNDelegate { countryPicker.setup(with: countryCodes) } + /// Set the example phone number type + public func set(exampleNumberType: NBEPhoneNumberType) { + self.exampleNumberType = exampleNumberType + + updatePlaceholder() + } + // Private @objc private func didEditText() { @@ -408,7 +416,7 @@ open class FPNTextField: UITextField, FPNCountryPickerDelegate, FPNDelegate { private func updatePlaceholder() { if let countryCode = selectedCountry?.code { do { - let example = try phoneUtil.getExampleNumber(countryCode.rawValue) + let example = try phoneUtil.getExampleNumber(forType: countryCode.rawValue, type: exampleNumberType) let phoneNumber = "+\(example.countryCode.stringValue)\(example.nationalNumber.stringValue)" if let inputString = formatter?.inputString(phoneNumber) {