🎯 Swift country and phone code Picker

Overview

CountryPicker

Swift Package Manager compatible Build Status Platform Swift version Swift version Beerpay

Picker code Swift 3 / 4 / 5.

Example

To run the example project, clone the repo, and run pod install from the Example directory first. 1

Usage

Make your UIPickerView a class of CountryPicker, set its countryPickerDelegate and implement its countryPhoneCodePicker method.

Example:

import CountryPicker

class ViewController: UIViewController, CountryPickerDelegate {

    @IBOutlet weak var picker: CountryPicker!
   
    
    override func viewDidLoad() {
        super.viewDidLoad()
       //get current country
        let locale = Locale.current
        let code = (locale as NSLocale).object(forKey: NSLocale.Key.countryCode) as! String?
        //init Picker
        picker.displayOnlyCountriesWithCodes = ["DK", "SE", "NO", "DE"] //display only
        picker.exeptCountriesWithCodes = ["RU"] //exept country
        let theme = CountryViewTheme(countryCodeTextColor: .white, countryNameTextColor: .white, rowBackgroundColor: .black, showFlagsBorder: false)        //optional for UIPickerView theme changes
        picker.theme = theme //optional for UIPickerView theme changes
        picker.countryPickerDelegate = self
        picker.showPhoneNumbers = true
        picker.setCountry(code!)

    }
    
    // a picker item was selected
    func countryPhoneCodePicker(_ picker: CountryPicker, didSelectCountryWithName name: String, countryCode: String, phoneCode: String, flag: UIImage) {
       //pick up anythink
      code.text = phoneCode
    }

}

Integration

CocoaPods (iOS 8+, OS X 10.9+)

CountryPicker is available through CocoaPods. To install

Swift 4-5 (Xcode 10+) pod 'CountryPickerSwift', '1.8'

Swift 3.1 (Xcode 9) pod 'CountryPickerSwift', '1.7'

Swift 3.0+ (Xcode 8) pod 'CountryPickerSwift', '1.4.4'

it, simply add the following line to your 'Podfile':

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
    pod 'CountryPickerSwift'
end

Swift Package Manager

You can use The Swift Package Manager to install CountryPicker by adding the proper description to your Package.swift file:

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    targets: [],
    dependencies: [
        .Package(url: "[email protected]:4taras4/CountryCode.git")
    ]
)

Note that the Swift Package Manager is still in early design and development, for more information checkout its GitHub Page

Manually

To use this library in your project manually just drag and drop CountryPicker folder to your project.

Author

4taras4, [email protected]

License

CountryPicker is available under the MIT license. See the LICENSE file for more info. release-link

Donate

Donation Bitcoin 141Q3KduSqvTtMbrU6YouSErDBh1SpiLrL

Support on Beerpay

Hey dude! Help me out for a couple of 🍻 !

Beerpay Beerpay

Comments
  • Wrong result when tapping on already selected row

    Wrong result when tapping on already selected row

    Currenlty delegate recevies wrong values, when users taps on selected row in picker. Delegate receives data for country 0, but app expects to see data for country actually tapped (in selected row)

    opened by IPv6 8
  • Crash while building release version

    Crash while building release version

    After updating to 1.7.3 I got this crash when building my app in release mode: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/3232DF58-CCEB-491A-8387-7100A0D31587/fototax.app/Frameworks/CountryPicker.framework> (loaded)' with name 'CountryView''

    opened by yulian948 3
  • No access to the CountryPicker using SPM

    No access to the CountryPicker using SPM

    Hello.

    I am trying to integrate a library using the Swift Package Manager from the master branch, everything looks good, but there is no way to access the source files for CountryPicker, only for the dummy CountryCode struct.

    opened by DmitryShapovalov 2
  • Carthage fix

    Carthage fix

    This library is really awesome. However there is an issue with using it with Carthage. This branch attempts to fix that, however I haven't tested it with Cocapods nor are the main line tests currently passing either.

    The way you make a library compatible for Carthage is simply by providing shared .framework targets in a project file. You already have a .framework target in your project file but it doesn't link to any of the source or bundle resources so this won't work. Additionally having a Cartfile in your framework / module is for including sub dependencies for your project. The Cartfile in the current master includes a recursive include of itself which stops Carthage from working in the first place. I don't see any dependencies in your project so you don't need a Cartfile.

    My branch is working for Carthage as we speak in Xcode 10.2.1 and Swift 5. If you want to test how a package works in Carthage check the documentation and make a simple test project and add your module to a Cartfile and see how it all works.

    E.g.

    # Cartfile
    github "madhavajay/CountryCode" "carthage-fix"
    

    Then run:

    $ carthage update --platform iOS
    

    If there are issues, you can simply modify the contents of the Checkout folder until its working and retry with:

    $ carthage build --platform iOS
    

    Regarding additional platforms all you need to do is add additional .framework targets for each platform in the Xcode Project file and ensure they have the same "Product Name" aka "CountryPickerSwift".

    What I would suggest is possibly refactoring the whole project to simplify a few things so you can support all 3 package managers together.

    I helped the author of GEOSwift with this recently and he has a nice example of a project that supports all three easily. https://github.com/GEOSwift/GEOSwift

    Unfortunately it's likely to be a few more years before SPM is the only package manager in use.

    Let me know if you have any questions about any of this stuff.

    opened by madhavajay 2
  • Load Bundle Crash

    Load Bundle Crash

    Inside

    fileprivate func loadViewFromNib() -> UIView {
            let bundle = Bundle(for: type(of: self))
            let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
            let nibView = nib.instantiate(withOwner: self, options: nil).first as! UIView
            
            return nibView
        }
    

    This error occures:

    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/F064407E-A951-47C1-8C3C-AD1938DD885F/MyApp.app> (loaded)' with name 'CountryView''


    opened by NTFLeo 2
  • Fix SPM support and request to tag 1.8.3

    Fix SPM support and request to tag 1.8.3

    • Fix SPM support to explicitly include CountryPicker.bundle as a resource, otherwise countryCodes.json may not be included. Because of the guard let on line 188 of CountryPicker.swift, failure to load the JSON silently fails and returns an empty Set.
    • Add conditionals to use Bundle.module when compiled with SPM.
    • Update Podspec for 1.8.3 and regenerate lockfiles. I would request that this be tagged as 1.8.3 at the same time, so that SPM will see the recent SPM-specific commits for that version, instead of having to just follow master.
    opened by synthemesc 1
  • SPM - Failed to resolve dependencies

    SPM - Failed to resolve dependencies

    When adding this repo to swift package manger, I get the following error : Failed to resolve dependencies because CountryCode >=1.4.3 contains incompatible tools version and root depends on CountryCode 1.8.2..<1.9.0, version solving failed.

    opened by ryancrunchi 1
  • picking and click bug

    picking and click bug

    Hi

    thank you for great repo. i added this repo to my app, but i found mini bug.

    i just picking to list and touch current selected object. wow selected first country.

    opened by zezeron 1
  • (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift

    (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift

    The .podspec does not define a swift version for the pod which causes the above error to appear when compiling a project which is importing CountryCode via cocoapods. You should consider adding the following to the .podspec to fix this issue:

    s.swift_version = '4.0'

    opened by kgellci 1
  • Countries order

    Countries order

    Hey,

    I have started using Country Picker and I have encountered two issues. I hope we can solve this.

    1. I am filtering countries in pickerView, so I have got Austria, Germany, Poland, Switzerland. Is there any way I can change order of these items? I guess it's preset alphabetically. I would like to begin with Germany.
    2. When I tap on a particular country in the row, I get phoneCode from the first item in that array. I mean, I have swiped on Switzerland, it gives me +41 as it should and when I tap on that Switzerland row I get phoneCode from Austria (+43). Same with others countries beside Austria which is first in that array.

    Here is my code:

    func countryPhoneCodePicker(_ picker: CountryPicker, didSelectCountryWithName name: String, 
         countryCode: String, phoneCode: String, flag: UIImage) {
        countryCodeButton.setTitle(phoneCode, for: .normal)
        countryImage.image = flag
    }
    
    
     func initPicker() {
        let locale = Locale.current
        guard let code = (locale as NSLocale).object(forKey: NSLocale.Key.countryCode) as! String? 
       else {
            return
          }
    
        countryPicker.displayOnlyCountriesWithCodes = StringConstants.codes.countryCodes
        countryPicker.countryPickerDelegate = self
        countryPicker.showPhoneNumbers = true
        countryPicker.setCountry(code)
    }
    
    opened by kovalskyy 1
  • feature/st picker theme

    feature/st picker theme

    In my project I need to customise an appearance of the picker views' rows, specifically colour of labels and the background colour. I've added a new struct, called CountryViewTheme. So now it's possible to change selected appearance attributes using following construction:

    let theme = CountryViewTheme(countryCodeTextColor: .white, countryNameTextColor: .white, rowBackgroundColor: .black, showFlagsBorder: false)
    countryPicker.theme = theme
    
    FEATURES 
    opened by stolkachov 1
Releases(1.8.4)
Owner
IOS Software developer. Open-source contributor.
null
A μlibrary in Swift containing all the countries with their localized name, ISO code, phone code, country code, flag image and emoji.

CountryKit CountryKit A μlibrary in Swift containing all the countries with their localized name, ISO code, phone code, country code, flag image and e

Alessandro 24 Nov 11, 2021
A country picker view controller for iOS

Planet A country picker view controller for iOS. Installation CocoaPods You can use CocoaPods to install Planet by adding it to your Podfile: platform

kWallet 71 Jul 11, 2022
MICountryPicker is a country picker controller for iOS8+ with an option to search.

MICountryPicker MICountryPicker is a country picker controller for iOS8+ with an option to search. The list of countries is based on the ISO 3166 coun

Mustafa Ibrahim 90 Mar 27, 2021
Convert Countries, Country Codes, Continents,... with a single line of code.

iOS · macOS · watchOS · tvOS A pure Swift library that allows you to easily convert Countries to Country Codes and Country Codes to Countries. There i

Novem 1 Feb 22, 2022
A SwiftUI List Picker to replace system Picker in List

BetterListPicker An alternative customizable list picker in order to replace built-in non customizable Picker when we write settings view codes. Demo

Jinya 1 Apr 11, 2022
A better SwiftUI Picker Use _Picker instead of Picker

BetterPicker A better SwiftUI Picker. Use _Picker instead of Picker. Create styles with _PickerStyle. The is a WIP This library is currently a work-in

Eric Lewis 17 Dec 14, 2022
A simple, customizable view for efficiently collecting country information in iOS apps.

CountryPickerView CountryPickerView is a simple, customizable view for selecting countries in iOS apps. You can clone/download the repository and run

Kizito Nwose 459 Dec 27, 2022
FYPhoto is a photo/video picker and image browser library for iOS written in pure Swift. It is feature-rich and highly customizable to match your App's requirements.

FYPhoto is a photo/video picker and image browser library for iOS written in pure Swift. It is feature-rich and highly customizable to match your App's requirements.

null 10 Dec 11, 2022
Elegant and Easy-to-Use iOS Swift Date Picker

D2PDatePicker Example To run the example project, clone the repo, and run pod install from the Example directory first. Example Code: Programmatical I

Pradheep Rajendirane 292 Nov 6, 2022
Multi-picker for iOS and Mac available in SwiftUI

Multi-picker for iOS and Mac available in Swift UI

1amageek 5 Jul 12, 2022
iOS/macOS media picker for importing images and videos in SwiftUI

iOS/macOS media picker for importing images and videos in SwiftUI.

Mobile Development Club 13 Dec 30, 2022
A simple yet customizable horizontal and vertical picker view

WheelPicker A simple yet customizable horizontal and vertical picker view Features Vertical or Horizontal picker Image or Text data Configure UILabel

Mind Studios 74 Sep 26, 2022
LocationPicker - A ready for use and fully customizable location picker for your app

LocationPicker A ready for use and fully customizable location picker for your app. Features Installation Cocoapods Carthage Swift Package Manager Qui

Zhuoran 397 Nov 16, 2022
Date picker dialog for iOS

DatePickerDialog 4.0 - iOS - Swift DatePickerDialog is an iOS drop-in classe that displays an UIDatePicker within an UIAlertView. Requirements DatePic

Squimer 535 Dec 17, 2022
a picker view shown as a popup for iOS in Objective-C

CZPicker Demo Change Log 3 most recent changes are listed here. Full change logs v0.4.3 - 2016-08-12 Added - (void)czpickerViewWillDisplay:(CZPickerVi

Chen Zeyu 527 Oct 2, 2022
An iOS picker view to serve all your "picking" needs

Mandoline The PickerView is a UICollectionView that provides a smooth "picking" interface. In order to get the most out of it, a consuming view contro

Blue Apron 883 Nov 28, 2022
A drop in single image picker.

PHSingleImagePicker A low memory, single image picker wrapper that provide a significant smaller file size while also preserve high image quality. Int

Phanith NY 0 Nov 6, 2021
React-native-place-picker: Pick any place with single click 🚀

React-native-place-picker: Pick any place with single click ??

b0iq 59 Dec 29, 2022
A SwiftUI implementation of a picker that also allows direct input.

ComboPicker ComboPicker is a SwiftUI view that allows users to input a value by selecting from a predefined set or by typing a custom one. Installatio

Alessio Moiso 5 Sep 13, 2022