Latest 1.1.0
License MIT
Platforms ios 8.0, osx 10.10

Earth is a library for picking names,dial codes,flags and emojis of countries all around the world. For both iOS and MacOS




  • Support 242 countries with flags, emojis and dial codes
  • Support 12 Languages. If it doesn’t cover your language, PR is welcomed.
  • CountryTextField class for picking country from a picker view
  • CountryPickerView allows you to select a country from a UITableView


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


  • iOS 8.0+ / macOS 10.10+
  • Swift 5.0+



CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

Earth is available through CocoaPods. To install
it, simply add the following line to your Podfile:


target '<Your Target Name>' do
pod 'Earth', '~> 1.1.0'

Then, run the following command:

$ pod install


Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Earth into your Xcode project using Carthage, specify it in your Cartfile:

github "leacode/Earth" ~> 1.1.0

Run carthage update to build the framework and drag the built Earth.framework into your Xcode project.

Swift Package Manager

Since Swift Package Manager is not support binding resources into frameworks. Vector flags are not available in this way.

dependencies: [
    .package(url: "", from: "1.1.0"),

How to use

  • Getting countries’ infomation (Support both Mac OS and iOS)
import Earth

// get all countries 
let countries = CountryKit.countries

// get a country with country code
if let country = "CN") {

     // use result here

     // get country's flag
     flagImageView.image = country.flag

     // get country's localized name
     countryTF.text = country.localizedName
  • Showing country picker (only support iOS for now)
let countryPicker = CountryPickerViewController()
countryPicker.pickerDelegate = self
present(countryPicker, animated: true, completion: nil)
  • Custmizing CountryTextField (only support iOS for now)

var settings = Picker.Settings()
// style
settings.barStyle = UIBarStyle.default  // Set toobar style
settings.displayCancelButton = true     // show cancel button or not

// font
settings.cellFont = UIFont.systemFont(ofSize: 15.0) // set font color

// text
settings.placeholder = "choose a country"  // set a placeholder for the text view
settings.doneButtonText = "Done"           // set done button text
settings.cancelButtonText = "Cancel"       // set cancel button text

// colors
settings.toolbarColor =                    // set toolbar color
settings.pickerViewBackgroundColor = UIColor.lightGray  // set background color of pickerView
settings.doneButtonColor = .white                       // set text color of done button
settings.cancelButtonColor = .purple                    // set text color of cancel button

// height
settings.rowHeight = 44.0                               // set row height

countryTF.settings = settings

Or you can just specify a textView as ‘CountryPicker’ and set it’s delegate ‘pickerDelegate’ to handle the result.

  • Custmizing CountryPickerViewController
let countryPicker = CountryPickerViewController()
countryPicker.pickerDelegate = self

var settings = CountryPickerViewController.Settings()

// style
settings.prefersLargeTitles = false
settings.hidesSearchBarWhenScrolling = false

// colors
settings.barTintColor = .orange
settings.cancelButtonColor = .white
settings.searchBarTintColor = .black

// texts
settings.searchBarPlaceholder = "搜索"
settings.title = "请选择国家"

// config
settings.showDialCode = true
settings.showFlags = true
settings.showEmojis = true

countryPicker.settings = settings

present(countryPicker, animated: true, completion: nil)


Chunyu Li


Earth is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "Earth",
    "version": "1.1.0",
    "swift_versions": "5.0",
    "summary": "A custmizable and easy to use framework contains Country Picker with awesome vector flags. Support both iOS and MacOS",
    "description": "It offers different kind of pickers for picking infomations about countries etc. You can access vector images of flags. It support 12 kinds of languages.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "leacode": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.1.0"
    "platforms": {
        "ios": "8.0",
        "osx": "10.10"
    "source_files": "Sources/Earth/*.swift",
    "ios": {
        "source_files": "Sources/ios/*.swift",
        "frameworks": [
    "resource_bundles": {
        "Earth": [
    "osx": {
        "frameworks": "AppKit"
    "swift_version": "5.0"

Pin It on Pinterest

Share This