ALCountryPicker
Country Picker
包含国旗和区号的全部国家列表。您可以通过名称、区域代码和区号搜索国家。您可以在不打开国家选择器的情况下获取您当前的国家。对于国旗,使用了 Emoji Unicode.Scalar。
需求
- iOS 10.0+
- Xcode 9+
- Swift 4+
示例
要运行示例项目,请先克隆仓库,然后在 Example 目录下运行 pod install
安装
ALCountryPicker 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中
pod 'ALCountryPicker'
入门指南
import UIKit
import ALCountryPicker
class ViewController: UIViewController {
@IBOutlet weak var countryLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
if let currentCountry = Country.current {
self.countryLabel.text = currentCountry.flag + " " + currentCountry.countryName + " (\(String(describing: currentCountry.dialingCode ?? "")))"
}
}
@IBAction func openCountry(_ sender: UIButton) {
CountryPicker.present(on: self) { (country) in
DispatchQueue.main.async {
print(country.dialingCode ?? "")
print(country.flag, "",country.countryName, "", country.countryCode)
self.countryLabel.text = country.flag + " " + country.countryName + " (\(String(describing: country.dialingCode ?? "")))"
}
}
}
}
gif
屏幕截图
您可以通过拨打代码、区代码和国家名称搜索国家。
作者
Abdul Shamim Khan
[email protected]
许可协议
ALCountryPicker 在MIT许可协议下可用。更多信息请参阅LICENSE文件。