/CityPicker

Custom Picker View for picking Countries and Cities worldwide

Primary LanguageSwiftMIT LicenseMIT

Language CI Status Version Mit License Platform

Requirements

Swift 2.0
iOS 8.0 +

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like CityPicker in your projects. See the Get Started section for more details.

Podfile

use_frameworks!

pod "CityPicker"

If you like to live on the bleeding edge, you can use the master branch with:

pod 'CityPicker', :git => 'https://github.com/salvonos/CityPicker'

Manually

  1. Clone, add as a submodule or download
  2. Add all the files under Classes to your project.
  3. Enjoy.

Usage

Copy the countriesToCities.json file into the CityPicker Pods Bundle Resources.

  1. Select Pods from the Project Navigator

  2. Select Target CityPicker

  3. Select tab Build Phases

  4. In Copy Bundle Resources import the json file countriesToCities.json from resorces folder

!!You must repeat these steps every time a pod is installed or updated

Import CityPicker in proper place.

import CityPicker

CityPicker is designed to be extremely easy to use. First create an instance of class CityPickerViewController, and then call it whenever you need it.

let cityPicker = CityPickerViewController()
@IBAction func showCityPicker(sender: AnyObject) {
        
        self.cityPicker.showCityPicker(self, backgroundColor: UIColor.clearColor(), blurView_hidden: false)
}

Delegate

The Delegate has 3 required functions. First add the CityPickerViewControllerDelegate in your class and you are ready to receive the selected values in your own class.

CityPickerDidSelectRow:
func CityPickerDidSelectRow(nation: String, city: String) {
        print("\(nation), \(city)")
    }
CityPickerDidPressedCancelButton:
func CityPickerDidPressedCancelButton() {
        print("canceled")
    }
CityPickerDidPressedSelectButton
func CityPickerDidPressedSelectButton(CityPicker: CityPickerViewController, nation: String, city: String) {
        cityLabel.text = "\(city), \(nation)"
    }

To Do

  • Support OS X
  • Convert UTF8 symbols in json List
  • Add missing cities

Contact

  • If you have some advice or you want to add a missing city open an issue or a PR.
  • Email [Salvo Nostrato](mailto: info@salvonostrato.com?subject=CityPicker)

Author

Salvo Nostrato, info@salvonostrato.com

License

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