Swiftpack.co - Package - leacode/Earth

Earth

An easy to use framework to pick names,dial codes,flags and emojis of countries all around the world.

CI Status Version License Platform

Alt text

Features

  • 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

Example

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

Requirements

  • iOS 8.0 and above.
  • Mac OS 10.10 and above.

Installation

CocoaPods

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:

use_frameworks!

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

Then, run the following command:

$ pod install

Carthage

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" ~> 0.1.6

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: "https://github.com/leacode/Earth.git", from: "0.1.6"),
]

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 = CountryKit.country(countryCode: "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 = UIColor.blue                    // 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)

Author

Chunyu Li

License

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

Github

link
Stars: 13
Help us keep the lights on

Dependencies

Used By

Total: