• Stars
    star
    296
  • Rank 140,464 (Top 3 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 7 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

CountryPicker

CountryPicker

Awesome Build Status

codecov Version Badge

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
  • Swift UI Support with example project

Requirements

  • iOS 11.0+ Support latest release iOS 16
  • latest Xcode 14.x 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' '~> 2.0.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.

    func presentCountryPickerScene(withSelectionControlEnabled selectionControlEnabled: Bool = true) {
        switch selectionControlEnabled {
        case true:
            // Present country picker with `Section Control` enabled
            CountryPickerWithSectionViewController.presentController(on: self, configuration: { countryController in
                countryController.configuration.flagStyle = .circular
                countryController.configuration.isCountryFlagHidden = !showCountryFlagSwitch.isOn
                countryController.configuration.isCountryDialHidden = !showDialingCodeSwitch.isOn
                countryController.favoriteCountriesLocaleIdentifiers = ["IN", "US"]

            }) { [weak self] country in
                
                guard let self = self else { return }
                self.countryImageView.isHidden = false
                self.countryImageView.image = country.flag
                self.countryCodeButton.setTitle(country.dialingCode, for: .normal)
            }
            
        case false:
            // Present country picker without `Section Control` enabled
            CountryPickerController.presentController(on: self, configuration: { countryController in
                countryController.configuration.flagStyle = .corner
                countryController.configuration.isCountryFlagHidden = !showCountryFlagSwitch.isOn
                countryController.configuration.isCountryDialHidden = !showDialingCodeSwitch.isOn
                countryController.favoriteCountriesLocaleIdentifiers = ["IN", "US"]

            }) { [weak self] country in
                
                guard let self = self else { return }
                
                self.countryImageView.isHidden = false
                self.countryImageView.image = country.flag
                self.countryCodeButton.setTitle(country.dialingCode, for: .normal)
            }
        }
    }
}

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.

CountryPickerWithSectionViewController.presentController(on: self, configuration: { controller in
    // Styling country flag image view
    controller.configuration.flagStyle = .circular 
    
    // Hide flag image view
    controller.configuration.isCountryFlagHidden = true
    
    // Hide country dial code
    controller.configuration.isCountryDialHidden = true
 })

Dependency Graph

Dependecy graph

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

More Repositories

1

UberCarAnimation

This app is for animating a car like uber from one position to another with preserving angle and smooth animation
Swift
59
star
2

GoogleDrivePhotoFetcher

This Project is aiming to download the photos from Google Drive using Google Sign In.
Swift
6
star
3

ReusableModules

Swift
4
star
4

SKSideMenu

Simple SideMenu Control.
Swift
4
star
5

MindfullnessTracker

Reading and writing Mindful Minutes from Appleโ€™s HealthKit
Swift
3
star
6

Reachability

Network framework apple
Swift
3
star
7

CryptoApp

CryptoApp using new swiftUI + combine
Swift
2
star
8

CoreDataTwitter

Practise core data for twitter like app
Swift
2
star
9

MVVMDemo

MVVM Architecture in iOS
Swift
2
star
10

MachineLearning

This project made for demo for Machine Learning with Swift IOS 11.
Swift
2
star
11

UIAnimationSamples

UIAnimation Examples
Swift
1
star
12

HomePageApp

Sample app for home page
Swift
1
star
13

RatingControl

Custom Control to take rating input from user
Swift
1
star
14

Notes

FullStack:- Server node.js database mongo with Swift
Swift
1
star
15

RangeSlider

RangeSlider Control for selecting range
Swift
1
star
16

iOS-Animation-By-Tutorials

Swift
1
star
17

CleanArchCatAppDemo

A Demo Cat list app with Clean Arch.
Swift
1
star
18

FirebaseChatApplication

Real-time Chat with Firebase
Swift
1
star
19

github-slideshow

A robot powered training repository ๐Ÿค–
HTML
1
star
20

Twitter

Self Learning Project
Swift
1
star
21

Portfolio

Greetings, Iโ€™m Suryakant. Iโ€™m a Software Engineer living in Chandigarh, India. I am a fan of ios, swift, and programming. I enjoy coffee while coding and cycling.
CSS
1
star
22

LearningProjectInIOS

Swift
1
star
23

AVL-Tree

AVL Tree in C++ .An AVL tree is a self-balancing binary search tree.
C++
1
star
24

CoordinatorPattern

Coordinator Pattern, Seperate tableView data Source from view controller, move view Code out of your view controller
Swift
1
star
25

QuizApp

Quiz app for practise TDD from courtesy of essentialDeveloper Acadamy
Swift
1
star
26

Runner

Application to record Track Workouts, earn badges. Small Application like version of https://runkeeper.com/
Swift
1
star
27

PractiseCode

Swift
1
star