Country Picker with dial code and flag for iOS.
- Localization ✅
- DarkMode support ⚫️⚪️
If you only want to present a picker and get the selected value you have to initialize a DHCountryPickerViewController
and set the delegate property.
let countryPickerViewController = DHCountryPickerViewController()
countryPickerViewController.delegate = self
present(UINavigationController(rootViewController: countryPickerViewController), animated: true, completion: nil)
If you need the selected country before showing the picker, you can use the current
property of DHCountryProvider
.
let countryProvider = DHCountryProvider()
selectedCountryLabel.text = countryProvider.current.localizedName
selectedCountryFlagImageView.image = countryProvider.current.flag
let countryPickerViewController = DHCountryPickerViewController(provider: countryProvider)
When the user changed the country, you can store it and next time present the picker with this value.
var selectedCountry: Country? // you can update this in the delegate method
let countryPickerViewController = DHCountryPickerViewController(selectedCountry: selectedCountry)
autoDismissOnSelect
- defaulttrue
- automatically dismiss the picker on selectionisDialCodeHidden
- defaulttrue
- show/hide the dial codes
let countryPickerViewController = DHCountryPickerViewController()
countryPickerViewController.autoDismissOnSelect = false
countryPickerViewController.isDialCodeHidden = false
CocoaPods:
pod 'DHCountryPicker'
- Swift 5
- iOS 11
- FlagKit - Flag images @madebybowtie
- CountryCodes - Dial codes @Goles
- Daniel Horvath - Twitter
This project is licensed under the MIT License - see the LICENSE.md file for details