Skip to content

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

License

Notifications You must be signed in to change notification settings

SURYAKANTSHARMA/CountryPicker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

CountryPicker

CountryPicker

Awesome Build Status

codecov Version Badge

Carthage compatible Swift Package Manager compatible License

CountryPicker is a Swift library that provides a simple and easy-to-use interface for selecting countries from a predefined list. It's perfect for adding country selection functionality to your iOS app with minimal effort.

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
  • Support Dynamic font size for ContentSizeCategory
  • Unit tests coverage 94%
  • Picker view support added with customization
  • Swift UI Support with example project
  • Rewritten with swiftUI and combine in version 3.0.0

Requirements

  • iOS 15.0+ Support latest release iOS 17 for older user older than 3.0.0
  • latest Xcode 15.x with Swift

Demo Project

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

Swift UI Combine new project

|

Screenshots

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

Installation

CountryPicker is available through Cocoapods and Carthage.

Add the following line to your Podfile:

For iOS 15 and above (Combine and Swiftui version) currently only supported by cocoapods 
pod 'SKCountryPicker'

Please note iOS 15 will be discontinued after in 2024.

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!

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

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

Getting Started

Please check baseiOS11Example project for customization and different option available for using with old uikit.

Please check baseiOS15Example project for using it in swift ui app with minimum deployment target iOS 15

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")

Dependency Graph

Dependecy graph

For swift ui

  • use 3.0.0 and above version

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

About

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

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages