A simple, customizable Country picker for picking country or dialing code. ๐Ÿ‡ฎ๐Ÿ‡ณ ๐Ÿ‡ฏ๐Ÿ‡ต ๐Ÿ‡ฐ๐Ÿ‡ท ๐Ÿ‡ฉ๐Ÿ‡ช ๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ‡บ๐Ÿ‡ธ ๐Ÿ‡ซ๐Ÿ‡ท ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‡ฎ๐Ÿ‡น ๐Ÿ‡ท๐Ÿ‡บ ๐Ÿ‡ฌ๐Ÿ‡ง

Overview

CountryPicker

CountryPicker

Awesome Travis CI codecov Version Carthage compatible Swift Package Manager compatible License

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.

If you like CountryPicker, give it a โ˜… at the top right of this page.

Features

  • Navigate through search and index title of section e.g (in Contact app in iOS)
  • Auto scroll to previous selected country
  • Filtering country options
  • Styling view options
  • Image size are optimized
  • Cocoa Pods integrated
  • Carthage integrated
  • Swift package manager integrated
  • Best practices followed
  • Dark mode supported in iOS 13
  • Support Dynamic font size for ContentSizeCategory
  • Unit tests coverage 94%
  • Picker view support added with customization

Requirements

  • iOS 10.0+ Support latest release iOS 13
  • Xcode 10.2+ Support latest Xcode 11 with Swift

Demo Project

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

Screenshots

Home Scene Country Picker Scene Filtering Scene Dark Mode Scene Picker View

Installation

CountryPicker is available through Cocoapods and Carthage.

CocoaPods:

Add the following line to your Podfile:

pod 'SKCountryPicker'

Current version compatible with Swift 5. If you want support Swift 4.1/3.3

pod 'SKCountryPicker' '~> 1.2.0'

Carthage

The steps required to use Carthage for dependency management are described here but lets add them to this README as well for good measure.

First you need to add the following line to your Cartfile

github "SURYAKANTSHARMA/CountryPicker"

to include the latest version of CountryPicker.

(if you don't have a Cartfile, you need to create one first in your favorite texteditor)

Next run

carthage update --platform iOS

This will have Carthage:

  • Fetch the source code for CountryPicker from Github
  • Compile the source code into a framework for you to use

once Carthage finishes building, you need to add the framework to your project.

In Xcode:

  • Navigate to the "General" tab of your project and tap the plus sign under "Frameworks, Libraries and Embedded Content"
  • Select "Add other" and locate the Carthage folder (typically in the root of your project)
  • The SKCountryPicker.framework is located under Carthage/Build/iOS/
  • Select it and verify that it is added as a framework.

The final step is to add the copy-frameworks build script to your "Build Phases".

  • Navigate to "Build Phases" and tap the + at the top.
  • Select "New Run Script Phase"
  • Paste this line as the script to run /usr/local/bin/carthage copy-frameworks
  • Add the SKCountryPicker.framework under Input Files like so: $(SRCROOT)/Carthage/Build/iOS/SKCountryPicker.framework

Done!

SPM

Add the following line to your Package.swift file in the dependencies section:

.package(url: "https://github.com/SURYAKANTSHARMA/CountryPicker.git, from "1.2.7")

Getting Started

Example: Please check example project for customization and different option available.

private extension ViewController {
    
    /// Dynamically presents country picker scene with an option of including `Selection Control`.
    ///
    /// By default, invoking this function without defining `selectionControlEnabled` parameter. Its set to `True`
    /// unless otherwise and the `Selection Control` will be included into the list view.
    ///
    /// - Parameter selectionControlEnabled: Section Control State. By default its set to `True` unless otherwise.
    
    func presentCountryPickerScene(withSelectionControlEnabled selectionControlEnabled: Bool = true) {
        switch selectionControlEnabled {
        case true:
            // Present country picker with `Section Control` enabled
            let countryController = CountryPickerWithSectionViewController.presentController(on: self) { [weak self] (country: Country) in
                
                guard let self = self else { return }
                
                self.countryImageView.isHidden = false
                self.countryImageView.image = country.flag
                self.countryCodeButton.setTitle(country.dialingCode, for: .normal)
            }
            
            countryController.flagStyle = .circular
            countryController.isCountryFlagHidden = !showCountryFlagSwitch.isOn
            countryController.isCountryDialHidden = !showDialingCodeSwitch.isOn
            countryController.favoriteCountriesLocaleIdentifiers = ["IN", "US"]
        case false:
            // Present country picker without `Section Control` enabled
            let countryController = CountryPickerController.presentController(on: self) { [weak self] (country: Country) in
                
                guard let self = self else { return }
                
                self.countryImageView.isHidden = false
                self.countryImageView.image = country.flag
                self.countryCodeButton.setTitle(country.dialingCode, for: .normal)
            }
            
            countryController.flagStyle = .corner
            countryController.isCountryFlagHidden = !showCountryFlagSwitch.isOn
            countryController.isCountryDialHidden = !showDialingCodeSwitch.isOn
            countryController.favoriteCountriesLocaleIdentifiers = ["IN", "US"]
        }
    }
}

Filter Options

There are 3 main filter options countryName, countryCode, countryDialCode and by default country picker has been configured to filter countries based on countryName.

If you want to add/remove filter options, do as follows:

 // Adding filter
 CountryManager.shared.addFilter(.countryCode)

 // Removing filter
 CountryManager.shared.removeFilter(.countryCode)

 // Removing all filters
 CountryManager.shared.clearAllFilters()

Incase you want to retrieve country info

// Get country based on digit code e.g: 60, +255
CountryManager.shared.country(withDigitCode: "255")

// Get country based on country name
CountryManager.shared.country(withName: "Tanzania")

// Get country based on country code e.g: MY, TZ
CountryManager.shared.country(withCode: "MY")

Styling Options

There are few styling options provided by the library such auto-hiding or styling views.

let countryController = CountryPickerWithSectionViewController.presentController(on: self) { ... }

// Styling country flag image view
countryController.flagStyle = .corner    // E.g .corner, ,circular or .normal

// Hide flag image view
countryController.isCountryFlagHidden = true // False

// Hide country dial code
countryController.isCountryDialHidden = true  // False

Contributing

Any contribution making project better is welcome.

Authors

*Suryakant Sharma

See also the list of contributors who participated in this project. Thanks from bottom of my heart to inspiration behind Hardeep Singh

License

This project is licensed under the MIT License - see the LICENSE file for details

Comments
  • Customization of countries list

    Customization of countries list

    This improvement will allow to customize countries list in more ways.

    class CustomCountryManager: CountryManager {
        //By overriding this method you can remove any country or add, or customize sorting, or even set your custom country class item
        override open func loadCountries() throws {
               let countryCodes = try! getCountryCodes()
            
               // Clear old loaded countries
               countries.removeAll()
            
               // Request for fresh copy of sorted country list
               let sortedCountries = countryCodes.map { Country(countryCode: $0) }.sorted { $0.countryName < $1.countryName }
                    
                //something like this
               sortedCountries.removeFirst()
    
                countries.append(contentsOf: sortedCountries)
        }
    
        //By overriding this method you can put any country codes not only from plist of library
        open func getCountryCodes() throws -> [String] {
                return []
        }
    }
    

    This will allow to use code like this:

       let countryManager = CustomCountryManager()
       do {
           try countryManager.loadCountries()
       } catch {
           #if DEBUG
               print(error.localizedDescription)
           #endif
       }
       CountryManager.shared = countryManager
    
    enhancement on review don't merge 
    opened by freakdragon 17
  • CountryManager is not loading countries correctly

    CountryManager is not loading countries correctly

    Hello!

    I'm having a problem, it seems like CountryManager is not loading countries correctly in my project. I tried to install by using CocoaPods and SPM and it remains the same. I guess it is a configuration problem.

    Console logs:

    " Could not load the "US.png" image referenced from a nib in the bundle with identifier "com.myproject.debug" "

    As I've tried, actually CountryManager.countries remain empty, so this is not only an image problem.

    If there's something I'm missing please, let me know.

    on review 
    opened by canedo2 17
  • Country list not loaded when using SPM

    Country list not loaded when using SPM

    I am using XCODE 11 'Add Swift Package' feature

    Country list is not loaded. I debugged and found that country.plist is not loaded. Getting log as "Missing contries file path"

    To Reproduce Steps to reproduce the behavior:

    1. Go to 'Xcode 11->File->Add Swift Package'
    2. Following integration steps to create country button and present country list
    3. Country list is not loaded

    Expected behavior Country list should be loaded

    Screenshots Screenshot 2020-04-28 at 3 45 51 AM

    Smartphone (please complete the following information):

    • Device: iPhone11
    • OS: 13.2.2
    bug help wanted good first issue Hacktoberfest 
    opened by kapadiamoheet 11
  • Instance no longer returned on `present(on:)` in 1.4.1

    Instance no longer returned on `present(on:)` in 1.4.1

    Describe the bug In 1.3.2 it was possible to retrieve the instance of the view controller after calling present:

    let countryController = CountryPickerWithSectionViewController.presentController(on: self) { ... }
    

    ^ that's from the README

    Now, the call returns ()

    If this is no longer supported, 1.4.1 should have been 2.0.0, as that's a breaking change

    good first issue beginner 
    opened by dhritzkiv 9
  • White search bar in dark mode

    White search bar in dark mode

    When the search field for the country list is visible the top bar background becomes white. Isn't it supposed to be black? How do we change it to black in dark mode?

    edit: when the table view controller is opening the top bar background is black, then when it finishes openning it becomes white...

    bug 
    opened by SerggioC 9
  • removing last selected country is not working

    removing last selected country is not working

    When I use this controller in two different places I want to remove the last selected country but cannot remove it. Can you please provide me with a way to do it.

    Thanking you in advance

    good first issue 
    opened by bhargavthakkar2912 8
  • Any hacktoberfest enthusiastic can contribute PRs on this repo

    Any hacktoberfest enthusiastic can contribute PRs on this repo

    Rules

    • Can reduce the launch time of pickerView (Please attach statistics if work)
    • Can add voice over accessibility
    • Test cases are recommended.
    • Add documentation of public apis by jazz (https://github.com/realm/jazzy)
    • Add value to project
    • No Spam
    help wanted good first issue Hacktoberfest beginner 
    opened by SURYAKANTSHARMA 8
  • No data when countries in Arabic language

    No data when countries in Arabic language

    No data when countries in Arabic language

    // This code is wrong
        func fetchSectionCountries() {
            for section in sections {
                let sectionCountries = countries.filter({ (country) -> Bool in
                    return country.countryName.first! == section
                })
                sectionCoutries[section] = sectionCountries
            }
        }
    
    
    bug 
    opened by Dev-Khaled 7
  • Favourite group in country code list

    Favourite group in country code list

    Please consider adding a "favorite" section. where we could set the favorites and it would display in the CountryPickerWithSectionViewController on the top.

    Great job on this project!!

    enhancement help wanted good first issue Hacktoberfest 
    opened by phillipjacobs 6
  • Unable to see check / tick mark for selected country

    Unable to see check / tick mark for selected country

    Describe the bug

    • Unable to see check / tick mark for selected country To Reproduce Steps to reproduce the behavior:
    1. Open country selection picker
    2. Select country
    3. Close picker
    4. Re-Open country selection picker
    5. Now you see no country is selected

    Expected behavior A clear and concise description of what you expected to happen.

    • Selected country should show check/tick mark

    Screenshots If applicable, add screenshots to help explain your problem.

    Screen_Recording_2022-09-30_at_8_01_18_AM_AdobeExpress

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

    bug good first issue Hacktoberfest 
    opened by vishalkevin11 5
  • A way of setting the last selected country

    A way of setting the last selected country

    I was wondering if there was a way / if you could make a way to set the last selected country. For example i want to show the picker but first i want to set the last selected country to another country before it is presented. I have already selected US for the country and when i show the controller again i want to set the selected country to UK instead because the field i am editing has UK as the selected country

    enhancement Hacktoberfest beginner 
    opened by joedefa01 5
Releases(2.0.0)
Owner
Suryakant
Open Source & Swift Enthusiast | iOS Engineer | Microsoft Student Partner| Indian yogi, Love to code with cup of tea. Write code with my whole heart.
Suryakant
๐ŸŽฏ Swift country and phone code Picker

CountryPicker Picker code Swift 3 / 4 / 5. Example To run the example project, clone the repo, and run pod install from the Example directory first. U

null 207 Dec 22, 2022
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
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
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 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
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
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
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
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 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