PKCountryPicker
一个基于 Swift 的助手类,它将提供世界上所有国家的相关信息,包括国旗、国家名称、国家代码、ISO 代码、NSN 限制等等。
要求
- iOS 10.0+
- Xcode 9.4
安装
对于手动安装,将 Source 文件夹拖拽到您的项目中。
或者使用 CocoaPod,将以下行添加到您的 Podfile
中
pod 'PKCountryPicker'
用法
开始加载
- 只需调用
chooseCountry()
方法,使用PKCountryPicker
的默认实例。
示例
PKCountryPicker.default.chooseCountry(onViewController: self) { (selectedCountry) in
print("selected country data: \(selectedCountry)")
}
设置修改配置
要修改选择器的默认配置,只需更改PKCountryPickerSettings
的值,例如:
重要属性
-
shouldAddPlusInCountryCode
用于决定是否在国家代码前使用“+”号。默认:true
-
toolbarHeight
用于指定工具栏的高度。默认:45.0
-
pickerSize
用于指定选择视图的大小。默认:CGSize(width: <屏幕宽度>, height: 240.0)
-
rowHeight
用于指定选择视图中每行的高度。默认:45.0
-
appearance
用于决定选择视图的样式。默认:PKCountryPickerAppearance.light
-
countryNameFont
用于设置国家名称文本的字体。默认:UIFont.systemFont(ofSize: 15.0)
-
countryNameColor
用于设置国家名称文本的颜色。默认:UIColor.black
-
countryCodeFont
用于设置国家代码文本的字体。默认:UIFont.systemFont(ofSize: 15.0)
-
countryCodeColor
用于设置国家代码文本的颜色。默认:UIColor.black
许可协议
PKCountryPicker遵循MIT许可协议发布。