CountryPickerIOS 1.0.4

CountryPickerIOS 1.0.4

Yehor Chernenko 维护。



  • Yehor Chernenko

CountryPickerIOS

CountryPickerIOS 是 CountryPickerView 的轻量级版本

屏幕截图

带有左侧视图的 UITextField

UITextFiled

CountryList, navBar 继承自 pushed vc

CountryList

安装

Cocoapods

CountryPickerView 可以通过 CocoaPods 使用。只需将以下内容添加到您的 Podfile 中

use_frameworks!

target '<Your Target Name>' do
  pod 'CountryPickerIOS`
end

手册

  1. 将 CountryPickerView 仓库放置在您的项目目录中的某个位置。
  2. 在 Xcode 中,将 CountryPickerView.xcodeproj 添加到您的项目中。
  3. 在您的应用目标上,将 CountryPickerView 框架
  • 在“通用”选项卡中作为嵌入的二进制文件添加
  • 在“构建阶段”选项卡中作为目标依赖项添加。

使用方法

如果您使用 Storyboards/Interface Builder,可以通过在 Storyboard 中添加 UIView 实例并然后在“工具”面板(右侧面板)的“身份检查器”选项卡的“自定义类”字段中手动将视图的类更改为 CountryPickerView 来创建 CountryPickerView 实例

您也可以通过编程方式创建 CountryPickerView 实例

import CountryPickerIOS

class ViewController: UIViewController {
    var countryPickerView: CountryPickerView?
    @IBOutlet weak var textField: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        countryPickerView = CountryPickerView(frame: CGRect(x: 0, y: 0, width: 100, height: textField.bounds.height))
        countryPickerView?.delegate = self
        
        //setting countryPickerView as left/right view of UITextField,
        //you also can add countryPickerView just as subview of another view
        textField.leftView = countryPickerView
        textField.leftViewMode = .always
    }

要显示国家选择器列表,您必须在您的 UIViewController 中遵守 CountryPickerListDelegate 协议,在 showCountryList(output: CountryPickerListOutput) 方法中创建 CountryPickerList 实例,并使用参数设置输出。

extension ViewController: CountryPickerListDelegate {
    func countryPickerView(_ countryPickerView: CountryPickerView, didSelectCountry country: Country) {
        debugPrint("Selected country \(country)")
    }
    
    func showCountryList(output: CountryPickerListOutput) {
        let countryList = CountryPickerList(style: .grouped)
        countryList.output = output
        
        navigationController?.pushViewController(countryList, animated: true)
    }   
}

许可证

CountryPickerView 在 MIT 许可证下分发。有关详情,请参阅 LICENSE