All Projects → chronotruck → Flagphonenumber

chronotruck / Flagphonenumber

Licence: apache-2.0
A formatted phone number UITextField with country flag picker.

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Flagphonenumber

PhoneCountryCodePicker
An iOS tableview picker for PhoneCountryCode (English & Chinese supported)
Stars: ✭ 31 (-91.64%)
Mutual labels:  country, picker, flags
Alerts And Pickers
Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...
Stars: ✭ 5,267 (+1319.68%)
Mutual labels:  picker, textfield
Qpdialcodepickerview
International Dial Code Picker View for Country or Area 国家或地区国际区号选择器
Stars: ✭ 15 (-95.96%)
Mutual labels:  country, picker
Countrycode
🎯 Swift country and phone code Picker
Stars: ✭ 175 (-52.83%)
Mutual labels:  flags, picker
Nkvphonepicker
An UITextField subclass to simplify country code's picking. Swift 5.0
Stars: ✭ 131 (-64.69%)
Mutual labels:  country, picker
Circle Flags
A collection of 300+ minimal circular SVG country flags
Stars: ✭ 139 (-62.53%)
Mutual labels:  country, flags
Countrypickerview
A simple, customizable view for efficiently collecting country information in iOS apps.
Stars: ✭ 397 (+7.01%)
Mutual labels:  country, picker
csc picker
A flutter package to display a country, states, and cities. In addition it gives the possibility to select a list of countries, States and Cities depends on Selected, also you can search country, state, and city all around the world.
Stars: ✭ 25 (-93.26%)
Mutual labels:  country, picker
flagpack
A lightweight flag icon toolkit for the web.
Stars: ✭ 51 (-86.25%)
Mutual labels:  country, flags
React Native Calendar Select
A component to select period from calendar like Airbnb
Stars: ✭ 279 (-24.8%)
Mutual labels:  picker
Pixel Picker
A tiny menu bar application that helps you pick colours from your screen! 🔍✨
Stars: ✭ 318 (-14.29%)
Mutual labels:  picker
Md Date Time Picker
An implementation of Material Design Picker components in vanilla CSS, JS, and HTML
Stars: ✭ 272 (-26.68%)
Mutual labels:  picker
Passwordtextfield
A custom TextField with a switchable icon which shows or hides the password and enforce good password policies
Stars: ✭ 281 (-24.26%)
Mutual labels:  textfield
Ngx Emoji Mart
Customizable Slack-like emoji picker for Angular
Stars: ✭ 322 (-13.21%)
Mutual labels:  picker
Grumble
A powerful modern CLI and SHELL
Stars: ✭ 277 (-25.34%)
Mutual labels:  flags
Name Suggestion Index
Canonical common brand names, operators, transit and flags for OpenStreetMap.
Stars: ✭ 332 (-10.51%)
Mutual labels:  flags
Colorpicker
jQuery UI widget for color picking (similar to the one in Microsoft Office 2010).
Stars: ✭ 271 (-26.95%)
Mutual labels:  picker
Bottomsheet Imagepicker
Modern image picker for Android
Stars: ✭ 267 (-28.03%)
Mutual labels:  picker
Horizontalpicker
A simple, customizable and easy to use picker where centre view is scaled up
Stars: ✭ 337 (-9.16%)
Mutual labels:  picker
Datetimepicker
jQuery Plugin Date and Time Picker
Stars: ✭ 3,402 (+816.98%)
Mutual labels:  picker

FlagPhoneNumber

FlagPhoneNumber is a phone number textfield with a fancy country code picker.

CI Status Version License Platform Language

🌅 Screenshot

🌍 Localization

Country names are displayed according to the phone language

📲 Example

To run the example project, clone the repo, and run pod install from the Example directory first.

⬇️ Installation

FlagPhoneNumber is available through CocoaPods and Carthage.

Carthage

Simply add in your Cartfile the following line:

github "chronotruck/FlagPhoneNumber"

Cocoapods

Simply add in your Podfile the following line:

pod "FlagPhoneNumber"

Manually

Simply import the Sources repository in your project.

👴🏻 Objective-C is supported

🗺 Usage

You can instantiate it in storyboards/xibs or programmatically:

let phoneNumberTextField = FPNTextField(frame: CGRect(x: 0, y: 0, width: view.bounds.width - 16, height: 50))

// You can change the chosen flag then set the phone number
phoneNumberTextField.setFlag(for: .FR)
phoneNumberTextField.set(phoneNumber: "0600000001")

// Or directly set the phone number with country code, which will update automatically the flag image
phoneNumberTextField.set(phoneNumber: "+33600000001")

🚨 FPNTextFieldDelegate

FPNTextFieldDelegate inherites from UITextFieldDelegate so nothing change:

phoneNumberTextField.delegate = self

It provides you three methods:

extension YourViewController: FPNTextFieldDelegate {

   /// The place to present/push the listController if you choosen displayMode = .list
   func fpnDisplayCountryList() {
      let navigationViewController = UINavigationController(rootViewController: listController)
      
      present(navigationViewController, animated: true, completion: nil)
   }

   /// Lets you know when a country is selected 
   func fpnDidSelectCountry(name: String, dialCode: String, code: String) {
      print(name, dialCode, code) // Output "France", "+33", "FR"
   }

   /// Lets you know when the phone number is valid or not. Once a phone number is valid, you can get it in severals formats (E164, International, National, RFC3966)
   func fpnDidValidatePhoneNumber(textField: FPNTextField, isValid: Bool) {
      if isValid {
         // Do something...         
         textField.getFormattedPhoneNumber(format: .E164),           // Output "+33600000001"
         textField.getFormattedPhoneNumber(format: .International),  // Output "+33 6 00 00 00 01"
         textField.getFormattedPhoneNumber(format: .National),       // Output "06 00 00 00 01"
         textField.getFormattedPhoneNumber(format: .RFC3966),        // Output "tel:+33-6-00-00-00-01"
         textField.getRawPhoneNumber()                               // Output "600000001"
      } else {
         // Do something...
      }
   }
}

🎨 Customization

By default, the picker view is showed but you can display the countries with a list view controller:

var listController: FPNCountryListViewController = FPNCountryListViewController(style: .grouped)

phoneNumberTextField.displayMode = .list // .picker by default

listController.setup(repository: textField.countryRepository)
listController.didSelect = { [weak self] country in
self?.textField.setFlag(countryCode: country.code)

Don't forget to implement the fpnDisplayCountryList:

func fpnDisplayCountryList() {
   let navigationViewController = UINavigationController(rootViewController: listController)

   listController.title = "Countries"

   self.present(navigationViewController, animated: true, completion: nil)
}

FlagKit is used by default but you can customize the list with your own flag icons assets:

// Be sure to set it before initializing a FlagPhoneNumber instance.
Bundle.FlagIcons = YOUR_FLAG_ICONS_BUNDLE

You can change the size of the flag button:

phoneNumberTextField.flagButtonSize = CGSize(width: 44, height: 44)

You can customize the inputAccessoryView of the textfield:

phoneNumberTextField.textFieldInputAccessoryView = getCustomTextFieldInputAccessoryView(with: items)

You can also customize the flag button's properties:

// This will freeze the flag.
// Only one particular country's phone numbers will be formatted and validated.
// You can set the country by setting the flag as shown earlier.
phoneNumberTextField.flagButton.isUserInteractionEnabled = false

You can have in the placeholder an example of a phone number according to the selected country or have your own placeholder:

phoneNumberTextField.hasPhoneNumberExample = false // true by default
phoneNumberTextField.placeholder = "Phone Number"

You can choose which country can appears in the list:

phoneNumberTextField.setCountries(including: [.FR, .ES, .IT, .BE, .LU, .DE])

Or exclude countries from the list:

phoneNumberTextField.setCountries(excluding: [.AM, .BW, .BA])

You can choose to display the country phone code in the picker or in the list view controller:

phoneNumberTextField.pickerView.showCountryPhoneCode = false // true by default
listController.showCountryPhoneCode = false // true by default

You can reuses FPN classes as you see fit !

☕️ Conception

This library uses libPhoneNumber-iOS library (https://github.com/iziz/libPhoneNumber-iOS)

Open source time proudly sponsored by Chronotruck.

💁🏻‍♂️ Author

grifas, [email protected]

Don't hesitate to contact me or make a pull request to upgrade this library.

📝 License

FlagPhoneNumber is available under the Apache license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].