DHCountryPicker 0.1.3

DHCountryPicker 0.1.3

Daniel 维护。



Build Status codecov

DHCountryPicker

带区号和国旗的 iOS 国家选择器。

  • 本地化
  • 暗黑模式支持⚫️⚪️

截图

用法

初始化

如果您只想显示选择器并获取所选值,您必须初始化一个 DHCountryPickerViewController 并设置代理属性。

let countryPickerViewController = DHCountryPickerViewController()
countryPickerViewController.delegate = self
present(UINavigationController(rootViewController: countryPickerViewController), animated: true, completion: nil)

如果您需要在显示选择器之前获取所选国家,您可以使用 DHCountryProvidercurrent 属性。

let countryProvider = DHCountryProvider()
selectedCountryLabel.text = countryProvider.current.localizedName
selectedCountryFlagImageView.image = countryProvider.current.flag

let countryPickerViewController = DHCountryPickerViewController(provider: countryProvider)

当用户更改国家时,您可以保存它,并在下次显示选择器时使用这个值。

var selectedCountry: Country? // you can update this in the delegate method
let countryPickerViewController = DHCountryPickerViewController(selectedCountry: selectedCountry)

可用的 ViewController 设置

  • autoDismissOnSelect - 默认 true - 在选择后自动关闭选择器
  • isDialCodeHidden - 默认 true - 显示/隐藏区号
let countryPickerViewController = DHCountryPickerViewController()
countryPickerViewController.autoDismissOnSelect = false
countryPickerViewController.isDialCodeHidden = false

安装

CocoaPods

pod 'DHCountryPicker'

需求

  • Swift 5
  • iOS 11

构建工具

作者

  • 丹尼尔·霍瓦斯 - 推特

许可

本项目遵守 MIT 许可协议 - 详细信息请参阅 LICENSE.md 文件