CocoaPods
pod 'GCCountryPicker'
实现
-
将 GCCountryPicker 添加到您的文件导入语句中。
import GCCountryPicker
-
创建 GCCountryPickerViewController 的实例。
let countryPickerViewController = GCCountryPickerViewController(displayMode: .withoutCallingCodes)
-
设置委托、数据源(可选)和导航标题。
countryPickerViewController.delegate = self countryPickerViewController.dataSource = self countryPickerViewController.navigationItem.title = "Countries"
-
将国家选择器视图控制器嵌入到导航控制器中。
let navigationController = UINavigationController(rootViewController: countryPickerViewController)
-
展示导航控制器。
self.present(navigationController, animated: true, completion: nil)
-
实现 GCCountryPickerDelegate。
func countryPickerDidCancel(_ countryPicker: GCCountryPickerViewController) func countryPicker(_ countryPicker: GCCountryPickerViewController, didSelectCountry country: GCCountry)
-
根据需要实现 GCCountryPickerDataSource。
func countryCodes(for countryPicker: GCCountryPickerViewController) -> [String]
文档
许可
GCCountryPicker 在 MIT 许可下可用。有关更多信息,请参阅许可文件。