Versions below 0.0.4 are Swift 2.2 compatible, versions 0.0.5-0.0.7 are Swift 3 compatible, versions 0.0.8+ are Swift 4 compatible.
To run the example project, clone the repo, and run pod install
from the Example directory first.
Make your UIPickerView a class of MRCountryPicker, set its countryPickerDelegate and implement its countryPhoneCodePicker method.
See the following example:
class ViewController: UIViewController, MRCountryPickerDelegate {
@IBOutlet weak var countryPicker: MRCountryPicker!
@IBOutlet weak var countryName: UILabel!
@IBOutlet weak var countryCode: UILabel!
@IBOutlet weak var countryFlag: UIImageView!
@IBOutlet weak var phoneCode: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
countryPicker.countryPickerDelegate = self
countryPicker.showPhoneNumbers = true
// set country by its code
countryPicker.setCountry("SI")
// optionally set custom locale; defaults to system's locale
countryPicker.setLocale("sl_SI")
// set country by its name
countryPicker.setCountryByName("Canada")
}
// a picker item was selected
func countryPhoneCodePicker(_ picker: MRCountryPicker, didSelectCountryWithName name: String, countryCode: String, phoneCode: String, flag: UIImage) {
self.countryName.text = name
self.countryCode.text = countryCode
self.phoneCode.text = phoneCode
self.countryFlag.image = flag
}
}
MRCountryPicker is available through Cocoapods and Carthage.
Add the following line to your Podfile:
pod 'MRCountryPicker', '~> 0.0.8'
Add the following line to your Cartfile:
github "xTrinch/MRCountryPicker" ~> 0.0.8
xtrinch, [email protected]
Made with a little help from my friends over at:
https://github.com/marmelroy/PhoneNumberKit
https://github.com/Keyflow/CountryPicker-iOS-Swift
https://github.com/nicklockwood/CountryPicker
MRCountryPicker is available under the MIT license. See the LICENSE file for more info.