A simple, customizable Country picker for picking country or dialing code.
This library is for country picker used in many app for selecting country code of user. User can select country by searching and then selecting country in list.
- Navigate through search and index title of section e.g (in Contact app in iOS)
- cocoa Pods integrated
- Best practices followed
- iOS 10.0+
- Xcode 9+
To run the example project, clone the repo, and run pod update from the Example directory first.
CountryPicker is available through Cocoapods.
Add the following line to your Podfile:
pod 'SKCountryPicker'
current version compatible with Swift 4.1 as well Swift 3.3
Example:
import UIKit
import SKCountryPicker
class ViewController: UIViewController {
//MARK:- IBOutlet
@IBOutlet weak var countryCodeButton: UIButton!
@IBOutlet weak var countryImageView: UIImageView!
let contryPickerController = CountryPickerController()
//MARK:- Func
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let country = CountryManager.shared.currentCountry
countryCodeButton.setTitle(country?.dialingCode, for: .normal)
countryImageView.image = country?.flag
countryCodeButton.clipsToBounds = true
}
@IBAction func countryCodeButtonClicked(_ sender: UIButton) {
let countryController = CountryPickerWithSectionViewController.presentController(on: self) { (country: Country) in
self.countryImageView.image = country.flag
self.countryCodeButton.setTitle(country.dialingCode, for: .normal)
}
// can customize the countryPicker here e.g font and color
countryController.detailColor = UIColor.red
}
}
Any contribution making project better is welcome.
In Example Project
Demo
Above is a Gif demo.
After running the project by default current country get selected as below.
On clicking on this button country picker open with the option of choose or filter the require country.
After selecting selected country with image will appear on your button.
See also the list of contributors who participated in this project. Thanks from bottom of my heart to inspiration behind Hardeep Singh
This project is licensed under the MIT License - see the LICENSE file for details