CountryPicker
选择器代码 Swift 3 / 4。
示例
要运行示例项目,请克隆仓库,然后首先从Example目录运行pod install
。
用法
将您的 UIPickerView 设置为 CountryPicker 类,设置其 countryPickerDelegate 并实现其 countryPhoneCodePicker 方法。
示例
import CountryPicker
class ViewController: UIViewController, CountryPickerDelegate {
@IBOutlet weak var picker: CountryPicker!
override func viewDidLoad() {
super.viewDidLoad()
//get current country
let locale = Locale.current
let code = (locale as NSLocale).object(forKey: NSLocale.Key.countryCode) as! String?
//init Picker
picker.displayOnlyCountriesWithCodes = ["DK", "SE", "NO", "DE"] //display only
picker.exeptCountriesWithCodes = ["RU"] //exept country
let theme = CountryViewTheme(countryCodeTextColor: .white, countryNameTextColor: .white, rowBackgroundColor: .black, showFlagsBorder: false) //optional for UIPickerView theme changes
picker.theme = theme //optional for UIPickerView theme changes
picker.countryPickerDelegate = self
picker.showPhoneNumbers = true
picker.setCountry(code!)
}
// a picker item was selected
func countryPhoneCodePicker(_ picker: CountryPicker, didSelectCountryWithName name: String, countryCode: String, phoneCode: String, flag: UIImage) {
//pick up anythink
code.text = phoneCode
}
}
集成
CocoaPods (iOS 8+, OS X 10.9+)
CountryPicker 可通过 CocoaPods 获取。要安装
Swift 4 (Xcode 10) pod 'CountryPickerSwift', '1.8'
Swift 3.1 (Xcode 9) pod 'CountryPickerSwift', '1.7'
Swift 3.0+ (Xcode 8) pod 'CountryPickerSwift', '1.4.4'
,只需将以下行添加到您的 'Podfile' 中
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
pod 'CountryPickerSwift'
end
Swift 包管理器
您可以使用 Swift 包管理器 通过将适当的描述添加到您的 Package.swift
文件中来安装 CountryPicker
import PackageDescription
let package = Package(
name: "YOUR_PROJECT_NAME",
targets: [],
dependencies: [
.Package(url: "[email protected]:4taras4/CountryCode.git")
]
)
请注意,Swift 包管理器 仍在早期设计和开发阶段,更多信息请查看其 GitHub 页面
手动安装
要将此库手动添加到您的项目中,只需将 CountryPicker 文件夹拖放到项目中即可。
作者
4taras4, [email protected]
许可
CountryPicker 在 MIT 许可证下可用。更多信息请参阅 LICENSE 文件。 发布链接
捐赠
比特币捐赠地址:141Q3KduSqvTtMbrU6YouSErDBh1SpiLrL
在Beerpay上支持
嘿哥们!帮帮我,给我一点...