Giter Club home page Giter Club logo

ios-country-code-picker's Introduction

iOS Country Code Picker

This is a iOS based CountryCode Picker which allows user to select country and enter mobile number.

Table of contents

iOS Support

Minimum iOS Target 13.0

Demo


Features

  • Select country with flag & country code

Getting started

Download this project and import required files in your project

Usage

Setup below configuration in your base viewcontroller

Create object of CountriesViewController

Create object of  CountriesViewController 
For Example,
 var countriesViewController = CountriesViewController()

Setup for opening country picker

e.g.

@IBAction func btnCountryPicker(_ sender: UIButton) {

    DispatchQueue.main.async {
        CountriesViewController.show(countriesViewController: self.countriesViewController, toVar: self)
    }
}

Setup delegate and implement methods for call back selected country details

  1. Will call when multiple countries can be selected func countriesViewController(_ countriesViewController: CountriesViewController, didSelectCountries countries: [Country])
  2. Will call when user cancel and close country picker func countriesViewControllerDidCancel(_ countriesViewController: CountriesViewController)
  3. Will call when country is selected func countriesViewController(_ countriesViewController: CountriesViewController, didSelectCountry country: Country)
  4. Will call when user deselect country func countriesViewController(_ countriesViewController: CountriesViewController, didUnselectCountry country: Country)

Setup your base class by extending your class with Delegate class

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!
   }
}

Create a Countries class which contain array of Country Object

e.g.

var countries: [Country] = []
countries.append(Country(countryCode: "AF", phoneExtension: "93", isMain: true, flag: emojiFlag(countryCode: "AF")))

Create a method for converting countryCode to unichar string

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

}

Create CountryModel object for store last selected country details

var selectedCountry:CountryModel?

Methods

Create a method for selected country details

private func getCountryAndName(_ countryParam: String? = nil) -> CountryModel?

Create a method for phone number validation

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)
}

Want to Contribute?

  • 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.

Need Help?

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.


Collection of Components

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.


Changelog

Detailed changes for each release are documented in CHANGELOG.

License

MIT

Keywords

Country Code, Country Code Picker, Picker demo, Country Picker ,WeblineIndia

ios-country-code-picker's People

Contributors

partners-wli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.