Very simple country picker for iOS with elegant design. It uses unicode for country flags.
- iOS 12+
- Xcode 12+
- Swift 5.3+
Currently CountryPicker is only avaliable via SPM. You can also add manually to your project.
If you have already Swift package set up, add CountryPicker as a dependency to your dependencies in your Package.swift file.
dependencies:[.package(url:"https://github.com/mobven/CountryPicker.git")]Simply, you present CountryPickerViewController. You can set default country for the picker with selectedCountry variable (Default value is "TR"). To get informed about country selection, you should conform to CountryPickerDelegate in your UIViewController.
letcountryPicker=CountryPickerViewController()
countryPicker.selectedCountry ="TR"
countryPicker.delegate =selfself.present(countryPicker, animated:true)To present CountryPickerViewController on SwiftUI, you need to create a CountryPicker representable. Check docs/SwiftUI out for details.
Delegate method will be called with country selection, you can update your outlets with new selected country model.
extensionViewController:CountryPickerDelegate{func countryPicker(didSelect country:Country){
countryTextField.text = country.isoCode.getFlag()+""+ country.localizedName
}}Default picker theme is supporting Dark Mode for iO13+ devices. You can easly customize the picker with editing Configuration properties. If you are adding custom colors, you should add dark appearance color for dark mode support.
publicprotocolConfiguration{varcountryNameTextColor:UIColor{getset}varcountryNameTextFont:UIFont{getset}varselectedCountryCodeBackgroundColor:UIColor{getset}varselectedCountryCodeTextColor:UIColor{getset}varselectedCountryCodeCornerRadius:CGFloat{getset}varcountryCodeFont:UIFont{getset}varcountryCodeTextColor:UIColor{getset}varcountryImageHeigth:CGFloat{getset}varcountryImageSpacing:CGFloat{getset}@available(*, deprecated, message:"Use `closeButtonStyle` instead")varcloseButtonTextColor:UIColor{getset}@available(*, deprecated, message:"Use `closeButtonStyle` instead")varcloseButtonFont:UIFont{getset}@available(*, deprecated, message:"Use `closeButtonStyle` instead")varcloseButtonText:String{getset}
// Default value .title(title: "Close", textColor: .systemGreen, font: .systemFont(ofSize: 16))
varcloseButtonStyle:DismissButtonStyle{getset}varcloseButtonAlignment:CloseButtonAlignment{getset}vartitleTextColor:UIColor{getset}vartitleFont:UIFont{getset}vartitleText:String{getset}varsearchBarPlaceholder:String{getset}varsearchBarBackgroundColor:UIColor{getset}varsearchBarPlaceholderColor:UIColor{getset}varsearchBarFont:UIFont{getset}varsearchBarHeight:CGFloat{getset}varsearchBarInsets:UIEdgeInsets{getset}varsearchBarLeftImage:UIImage?{getset}varsearchIconHeight:CGFloat{getset}varsearchBarClearImage:UIImage?{getset}varsearchBarCornerRadius:CGFloat{getset}varsearchBarBorderColor:UIColor{getset}varsearchBarBorderWidth:CGFloat{getset}@available(*, deprecated, message:"Use `seperatorAppearance` instead")varseparatorColor:UIColor{getset}varseperatorAppearance:SeperatorAppearance{getset}
// Default value true.
varshowPhoneCodes:Bool{getset}varseperatorInsets:UIEdgeInsets{getset}
// Default value .orderedSame
varcountriesSortingComparisonResult:ComparisonResult{getset}}You can customize properties like this,
CountryManager.shared.config.countryNameTextColor =.black
CountryManager.shared.config.countryNameTextFont =UIFont.systemFont(ofSize:16)or you can create your own Config
letconfigMaker=Config(
countryNameTextColor:.black,
countryNameTextFont:UIFont.systemFont(ofSize:16),
selectedCountryCodeBackgroundColor:.green
)CountryManager.shared.config =configMaker()getCountries() method in CountryManager will return a Country array for you, so you can create your own custom UI implementations with this array.
letcountries=CountryManager.shared.getCountries()CountryPicker uses unicode for country flags. You can use with iso codes like the example below.
label.text ="US".getFlag()CountryPicker is use current NSLocale for localization of country name, you can set custom locale before presenting picker.
CountryManager.shared.localeIdentifier ="en_US"letcountryPicker=CountryPickerViewController()self.present(countryPicker, animated:true)For page title and close button text you can set localized text with Configration properties
CountryManager.shared.config.titleText ="Country Picker"CountryManager.shared.config.closeButtonStyle =.title(title:"Close", textColor:.red, font:.systemFont(ofSize:16))CountryPicker v1.0.0 is support RTL except displaying localized phone codes.
- Sample Project.
- SwiftUI representable code example.
- Support below iOS 13.
Developed with 🖤 at Mobven


