{"id":2678,"url":"https://github.com/kizitonwose/CountryPickerView","last_synced_at":"2025-08-06T14:32:54.003Z","repository":{"id":46635122,"uuid":"106047945","full_name":"kizitonwose/CountryPickerView","owner":"kizitonwose","description":"A simple, customizable view for efficiently collecting country information in iOS apps.","archived":false,"fork":false,"pushed_at":"2023-10-16T08:59:50.000Z","size":2298,"stargazers_count":513,"open_issues_count":16,"forks_count":200,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-08-04T07:57:01.801Z","etag":null,"topics":["country","country-information","country-list","country-picker","flag","phone","picker"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kizitonwose.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-06T20:33:06.000Z","updated_at":"2025-06-30T20:31:23.000Z","dependencies_parsed_at":"2024-06-18T12:31:07.802Z","dependency_job_id":"0d1201d7-1bef-4dc2-85d6-7f70b5178d3f","html_url":"https://github.com/kizitonwose/CountryPickerView","commit_stats":{"total_commits":175,"total_committers":16,"mean_commits":10.9375,"dds":"0.14857142857142858","last_synced_commit":"711740bcca36626c99a4901c8fc9fbc880a2debb"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/kizitonwose/CountryPickerView","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kizitonwose%2FCountryPickerView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kizitonwose%2FCountryPickerView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kizitonwose%2FCountryPickerView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kizitonwose%2FCountryPickerView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kizitonwose","download_url":"https://codeload.github.com/kizitonwose/CountryPickerView/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kizitonwose%2FCountryPickerView/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268883495,"owners_count":24323147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["country","country-information","country-list","country-picker","flag","phone","picker"],"created_at":"2024-01-05T20:16:19.957Z","updated_at":"2025-08-06T14:32:53.638Z","avatar_url":"https://github.com/kizitonwose.png","language":"Swift","funding_links":[],"categories":["UI","Libs","UI [🔝](#readme)"],"sub_categories":["PickerView","UI","Other free courses"],"readme":"# CountryPickerView\n\n[![Build Status](https://travis-ci.org/kizitonwose/CountryPickerView.svg?branch=master)](https://travis-ci.org/kizitonwose/CountryPickerView)\n[![Platform](https://img.shields.io/badge/Platform-iOS-00BCD4.svg)](http://cocoapods.org/pods/CountryPickerView)\n[![Version](https://img.shields.io/cocoapods/v/CountryPickerView.svg?style=flat)](http://cocoapods.org/pods/CountryPickerView)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![SPM compatible](https://img.shields.io/badge/SPM-compatible-4BC51D.svg?style=flat)](https://swift.org/package-manager)\n[![License](https://img.shields.io/badge/License-MIT-8D6E63.svg)](https://github.com/kizitonwose/CountryPickerView/blob/master/LICENSE.md)\n\nCountryPickerView is a simple, customizable view for selecting countries in iOS apps.\n\nYou can clone/download the repository and run the [demo project](https://github.com/kizitonwose/CountryPickerView/tree/master/CountryPickerViewDemo) to see CountryPickerView in action. First run `pod install` from the CountryPickerViewDemo directory.\n\n\u003cimg align=\"left\" src=\"https://raw.githubusercontent.com/kizitonwose/CountryPickerView/master/CountryPickerViewDemo/Screenshots/1.png\" width=\"300\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/kizitonwose/CountryPickerView/master/CountryPickerViewDemo/Screenshots/2.png\" width=\"300\"\u003e\n\n\u003cimg align=\"left\" src=\"https://raw.githubusercontent.com/kizitonwose/CountryPickerView/master/CountryPickerViewDemo/Screenshots/3.png\" width=\"300\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/kizitonwose/CountryPickerView/master/CountryPickerViewDemo/Screenshots/4.png\" width=\"300\"\u003e\n\n\n## Installation\n\n\u003e Note that 3.x releases are Swift 5 compatible. For the Swift 4 compatibility, use 2.x releases. For the Swift 3 compatibility, use 1.x releases.\n\n### Swift Package Manager\n[Swift Package Manager](https://swift.org/package-manager) is a dependency manager built into Xcode.\n\nIf you are using Xcode 11 or higher, go to `File / Swift Packages / Add Package Dependency…` and enter package repository URL `https://github.com/kizitonwose/CountryPickerView.git` then follow the instructions.\n\n### Cocoapods\n\nCountryPickerView is available through [CocoaPods](http://cocoapods.org). Simply add the following to your Podfile:\n\n```ruby\nuse_frameworks!\n\ntarget '\u003cYour Target Name\u003e' do\n  pod 'CountryPickerView'\nend\n```\n\n### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.\n\nTo install CountryPickerView through Carthage, simply add the following to your Cartfile:\n\n```ruby\ngithub \"kizitonwose/CountryPickerView\"\n```\n\n### Manual\n\n1. Put CountryPickerView repo somewhere in your project directory.\n2. In Xcode, add `CountryPickerView.xcodeproj` to your project.\n3. On your app's target, add the CountryPickerView framework:\n   1. as an embedded binary on the General tab.\n   2. as a target dependency on the Build Phases tab.\n\n## Usage\n\nIf you're using Storyboards/Interface Builder you can create a CountryPickerView instance by adding a UIView to your Storyboard, and then manually changing the view's class to CountryPickerView in the \"Custom Class\" field of the Identity Inspector tab on the Utilities panel (the right-side panel)\n\nYou can also create an instance of CountryPickerView programmatically:\n\n```swift\nimport CountryPickerView\n\nlet cpv = CountryPickerView(frame: /**Desired frame**/)\n```\n\nTo get the selected country from your `CountryPickerView` instance at any time, use the `selectedCountry` property.\n\n```swift\nlet country = cpv.selectedCountry\nprint(country)\n```\nThis property is not optional, the default value is the user's current country, derived from the device's current Locale.\n\n### Customization\n\nCustomization options for the view itself are available directly via the CountryPickerView instance while options for the internal CountryPicker table view are available via the `CountryPickerViewDataSource` protocol. Setting the `CountryPickerViewDelegate` protocol is also necessary if you wish to be notified when the user selects a country from the list.\n\n```swift\nimport CountryPickerView\n\nclass DemoViewController: UIViewController, CountryPickerViewDelegate, CountryPickerViewDataSource {\n\n    @IBOutlet weak var countryPickerView: CountryPickerView!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        countryPickerView.delegate = self\n        countryPickerView.dataSource = self\n    }\n}\n```\n\n#### CountryPickerView properties\n\n|Property|Description|Default value|\n|:-:|:-:|:-:|\n|showCountryCodeInView|Show or hide the country code(e.g NG) on the view.|true|\n|showPhoneCodeInView|Show or hide the phone code(e.g +234) on the view.|true|\n|showCountryNameInView|Show or hide the country name(e.g Nigeria) on the view.|false|\n|font|The font of the phone/country code text.|system font|\n|textColor|The color of the phone/country code text.|black|\n|flagSpacingInView|The spacing between the flag image and the phone code text.|8px|\n|hostViewController|The view controller used to show the internal `CountryPickerViewController`. If this is an instance of `UINavigationController`, the `CountryPickerViewController` will be pushed on the stack. If not, the `CountryPickerViewController` will be presented on its own navigation stack. If this property is `nil`, the view will try to find the nearest view controller and use that to present or push the `CountryPickerViewController`.|nil|\n|delegate|An instance of `CountryPickerViewDelegate` type.|nil|\n|dataSource|An instance of `CountryPickerViewDataSource` type.|nil|\n\nNote: The properties `showCountryCodeInView` and `showCountryNameInView` can't both be enabled at the same time. Enabling one to will disable the other. You can only show all properties on the list(see `CountryPickerViewDataSource`).\n\n#### CountryPickerViewDelegate\n- Called when the user selects a country from the list or when you manually set the `selectedCountry` property of the `CountryPickerView`\n\n  ```swift\n  func countryPickerView(_ countryPickerView: CountryPickerView, didSelectCountry country: Country)\n  ```\n\n- Called before the CountryPickerViewController is presented or pushed. The CountryPickerViewController is a UITableViewController subclass.\n  \n  ```swift\n  func countryPickerView(_ countryPickerView: CountryPickerView, willShow viewController: CountryPickerViewController)\n  ```\n\n- Called after the CountryPickerViewController is presented or pushed. The CountryPickerViewController is a UITableViewController subclass.\n  \n  ```swift\n  func countryPickerView(_ countryPickerView: CountryPickerView, didShow viewController: CountryPickerViewController)\n  ```\n\n**Note: If you already have a `Country` class or struct in your project then implementing the `didSelectCountry` delegate method can cause a compile error with a message saying that your conforming class does not comform to the `CountryPickerViewDelegate` protocol. This is because Xcode can't figure out which Country model to use in the method. The solution is to replace the `Country` in the method signature with the typealias `CPVCountry`, your delegate method should now look like this:**\n\n```swift\nfunc countryPickerView(_ countryPickerView: CountryPickerView, didSelectCountry country: CPVCountry)\n``` \n  \n  You can also use `CPVCountry` as a replacement for the framework's `Country` model in other parts of your project.\n\nAlso, `willShow` and `didShow` delegate methods are optional. If the CountryPickerViewController is presented(not pushed), it is embedded in a UINavigationController.\nThe `CountryPickerViewController` class is made available so you can customize its appearance if needed. You can also access the public `searchController(UISearchController)` property in the `CountryPickerViewController` for customization.\n\n\n#### CountryPickerViewDataSource\nThe datasource methods define the internal(country list) ViewController's behavior. Run the demo project to play around with the options. All methods are optional.\n\n- An array of countries you wish to show at the top of the list. This is useful if your app is targeted towards people in specific countries.\n  \n  ```swift\n  func preferredCountries(in countryPickerView: CountryPickerView) -\u003e [Country]\n  ```\n\n- The desired title for the preferred section.\n  \n  ```swift  \n  func sectionTitleForPreferredCountries(in countryPickerView: CountryPickerView) -\u003e String?\n  ```\n  **Note:** You have to return a non-empty array of countries from `preferredCountries(in countryPickerView: CountryPickerView)` as well as this section title if you wish to show preferred countries on the list. Returning only the array or title will not work.\n\n- Show **ONLY** the preferred countries section on the list. Default value is `false`\n  \n  ```swift  \n  func showOnlyPreferredSection(in countryPickerView: CountryPickerView) -\u003e Bool\n  ```\n  Return `true` to hide the internal list so your users can only choose from the preferred countries list.\n\n- The desired font for the section title labels on the list. Can be used to configure the text size.\n  \n  ```swift  \n  func sectionTitleLabelFont(in countryPickerView: CountryPickerView) -\u003e UIFont\n  ```\n\n- The desired text color for the section title labels on the list.\n  \n  ```swift  \n  func sectionTitleLabelColor(in countryPickerView: CountryPickerView) -\u003e UIColor?\n  ```\n\n- The desired font for the cell labels on the list. Can be used to configure the text size.\n  \n  ```swift  \n  func cellLabelFont(in countryPickerView: CountryPickerView) -\u003e UIFont\n  ```\n\n- The desired text color for the country names on the list.\n  \n  ```swift  \n  func cellLabelColor(in countryPickerView: CountryPickerView) -\u003e UIColor?\n  ```\n\n- The desired size for the flag images on the list.\n  \n  ```swift  \n  func cellImageViewSize(in countryPickerView: CountryPickerView) -\u003e CGSize\n  ```\n\n- The desired corner radius for the flag images on the list.\n  \n  ```swift  \n  func cellImageViewCornerRadius(in countryPickerView: CountryPickerView) -\u003e CGFloat\n  ```\n\n- The navigation item title when the internal view controller is pushed/presented. Default value is `nil`\n  \n  ```swift   \n  func navigationTitle(in countryPickerView: CountryPickerView) -\u003e String?\n  ```\n\n- A navigation item button to be used if the internal view controller is presented(not pushed). If nil is returned, a default \"Close\" button is used. This method only enables you return a button customized the way you want. Default value is `nil`\n  \n  ```swift    \n  func closeButtonNavigationItem(in countryPickerView: CountryPickerView) -\u003e UIBarButtonItem?\n  ```\n  **Note:** Any `target` or `action` associated with this button will be replaced as this button's sole purpose is to close the internal view controller.\n\n- Desired position for the search bar. Default value is `.tableViewHeader`\n  \n  ```swift    \n  func searchBarPosition(in countryPickerView: CountryPickerView) -\u003e SearchBarPosition\n  ```\n  Possible values are: `.tableViewHeader`, `.navigationBar` and `.hidden`\n\n- Show the phone code alongside the country name on the list. e.g Nigeria (+234). Default value is `false`\n  \n  ```swift    \n  func showPhoneCodeInList(in countryPickerView: CountryPickerView) -\u003e Bool\n  ```\n\n- Show the country code alongside the country name on the list. e.g Nigeria (NG). If `true`, searches are also performed against the country codes. Default value is `false`\n  \n  ```swift    \n  func showCountryCodeInList(in countryPickerView: CountryPickerView) -\u003e Bool\n  ```\n\n- Show a checkmark on the selected country on the list. Default value is `true`\n  \n  ```swift    \n  func showCheckmarkInList(in countryPickerView: CountryPickerView) -\u003e Bool\n  ```\n\n- The locale used to display country names on the list. Default value is the current locale.\n  \n  ```swift    \n  func localeForCountryNameInList(in countryPickerView: CountryPickerView) -\u003e Locale\n  ```\n\n### Using CountryPickerView with UITextField\n\nA good use case for `CountryPickerView` is when used as the left view of a phone number input field.\n\n```swift\nclass DemoViewController: UIViewController {\n\n    @IBOutlet weak var phoneNumberField: UITextField!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        let cpv = CountryPickerView(frame: CGRect(x: 0, y: 0, width: 120, height: 20))\n        phoneNumberField.leftView = cpv\n        phoneNumberField.leftViewMode = .always\n    }\n}\n```\nThis means your users do not have to worry about entering the country's phone code in the text field. This also ensures you get a valid phone code from `CountryPickerView` instead of relying on your users.\n\n### Using the internal picker independently\n\nIf for any reason you do not want to show the default view or have your own implementation for showing country information, you can still use the internal picker to allow your users select countries from the list by calling the method `showCountriesList(from: UIViewController)` on a `CountryPickerView` instance.\n\nIt's important to keep a field reference to the `CountryPickerView` instance else it will be garbage collected and any attempt to use it will result to a crash.\n\n```swift\nclass DemoViewController: UIViewController {\n\n    // Keep a field reference\n    let countryPickerView = CountryPickerView()\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n    }\n\n    @IBAction func buttonPressed(_ sender: Any) {\n        countryPickerView.showCountriesList(from: self)\n    }\n}\n```\nIn the example above, calling `countryPickerView.showCountriesList(from: self)` will result in the internal picker view controller being presented in its own navigation stack because `DemoViewController` is not a navigation controller.\n\nIf you already have a navigation stack, you can push the internal picker view controller onto that stack by calling `countryPickerView.showCountriesList(from: self.navigationController!)` or do it the safe way:\n\n```swift\nif let nav = self.navigationController {\n\tcountryPickerView.showCountriesList(from: nav)\n}\n```\nDon't forget to set a delegate to be notified when the use selects a country from the list. An example of how to use the internal picker view controller is included in the demo project.\n\n\n### Creating Country instances\n\nYou can create `Country` instances with any of these methods in `CountryPickerView` class:\n\n```swift\nlet countryPickerView = CountryPickerView()\nlet country = countryPickerView.getCountryByName(\"Nigeria\")\nlet country2 = countryPickerView.getCountryByCode(\"NG\")\nlet country3 = countryPickerView.getCountryByPhoneCode(\"+234\")\n```\n\nYou can also set the selected country using these helper methods:\n\n```swift\nlet countryPickerView = CountryPickerView()\ncountryPickerView.setCountryByName(\"Nigeria\")\ncountryPickerView.setCountryByCode(\"NG\")\ncountryPickerView.setCountryByPhoneCode(\"+234\")\n```\n\n## License\n\nCountryPickerView is distributed under the MIT license. [See LICENSE](https://github.com/kizitonwose/CountryPickerView/blob/master/LICENSE.md) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkizitonwose%2FCountryPickerView","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkizitonwose%2FCountryPickerView","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkizitonwose%2FCountryPickerView/lists"}