This is a iOS based CountryCode Picker which allows user to select country and enter mobile number.
- iOS Support
- Demo
- Features
- Getting started
- Usage
- Methods
- Want to Contribute?
- Need Help / Support?
- Collection of Components
- Changelog
- License
- Keywords
Minimum iOS Target 13.0
- Select country with flag & country code
Download this project and import required files in your project
Setup below configuration in your base viewcontroller
Create object of CountriesViewController
For Example,
var countriesViewController = CountriesViewController()
e.g.
@IBAction func btnCountryPicker(_ sender: UIButton) {
DispatchQueue.main.async {
CountriesViewController.show(countriesViewController: self.countriesViewController, toVar: self)
}
}
- Will call when multiple countries can be selected func countriesViewController(_ countriesViewController: CountriesViewController, didSelectCountries countries: [Country])
- Will call when user cancel and close country picker func countriesViewControllerDidCancel(_ countriesViewController: CountriesViewController)
- Will call when country is selected func countriesViewController(_ countriesViewController: CountriesViewController, didSelectCountry country: Country)
- Will call when user deselect country func countriesViewController(_ countriesViewController: CountriesViewController, didUnselectCountry country: Country)
e.g.
func setupCountryPicker(){
self.countriesViewController = CountriesViewController()
self.countriesViewController.delegate = self
self.countriesViewController.allowMultipleSelection = false
if let info = self.getCountryAndName() {
countryCode = info.countryCode!
self.lblFlag.text = info.countryFlag!
self.lblCountryCode.text = info.countryCode!
}
}
e.g.
var countries: [Country] = []
countries.append(Country(countryCode: "AF", phoneExtension: "93", isMain: true, flag: emojiFlag(countryCode: "AF")))
e.g.
open class func emojiFlag(countryCode: String) -> String {
let base : UInt32 = 127397
var string = ""
let country = countryCode.uppercased().unicodeScalars
for uS in country {
print("country code:\(countryCode.uppercased())---\(UnicodeScalar(base + uS.value)!)")
string.unicodeScalars.append(UnicodeScalar(base + uS.value)!)
}
return string
}
var selectedCountry:CountryModel?
private func getCountryAndName(_ countryParam: String? = nil) -> CountryModel?
func isValidPhone(phone: String) -> Bool {
let phoneRegex = "^[0-9+]{0,1}+[0-9]{9}$"
let phoneTest = NSPredicate(format: "SELF MATCHES %@", phoneRegex)
return phoneTest.evaluate(with: phone)
}
- Created something awesome, made this code better, added some functionality, or whatever (this is the hardest part).
- Fork it.
- Create new branch to contribute your changes.
- Commit all your changes to your branch.
- Submit a pull request.
We also provide a free, basic support for all users who want to use this country picker demo in project. In case you want to customize this country picker demo input to suit your development needs, then feel free to contact our iOS developers.
We have built many other components and free resources for software development in various programming languages. Kindly click here to view our Free Resources for Software Development.
Detailed changes for each release are documented in CHANGELOG.
Country Code, Country Code Picker, Picker demo, Country Picker ,WeblineIndia