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
}
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.
Earth
Earth is a library for picking names,dial codes,flags and emojis of countries all around the world. For both iOS and MacOS
Features
Example
To run the example project, clone the repo, and run
pod install
from the Example directory first.Requirements
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
Earth is available through CocoaPods. To install it, simply add the following line to your Podfile:
Then, run the following command:
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:
To integrate Earth into your Xcode project using Carthage, specify it in your
Cartfile
:Run
carthage update
to build the framework and drag the builtEarth.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.
How to use
Or you can just specify a textView as ‘CountryPicker’ and set it’s delegate ‘pickerDelegate’ to handle the result.
Author
Chunyu Li
License
Earth is available under the MIT license. See the LICENSE file for more info.