PickerController 0.1.2

PickerController 0.1.2

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最近发布2017年1月
SwiftSwift版本3.0
SPM支持SPM

Wonder Bear维护。



  • 作者
  • xiongxiong

PickerController

PickerController,可以实现关联选择。我非常喜欢它。

PickerController

内容

特点

  • [x] 关联选择器支持
  • [x] 分组选择器支持
  • [x] 日期选择器支持

需求

  • iOS 8.0+/ Mac OS X 10.11+/ tvOS 9.0+
  • Xcode 8.0+
  • Swift 3.0+

安装

手动安装

如果您不希望使用上述任何一个依赖管理器,您可以手动将PickerController集成到项目中。

示例

打开示例项目,构建并运行。

用法

UIViewController扩展

extension UIViewController {

    public func showCorrelationPicker(title:String, correlationalJsonStr: String, selectedItems: [String], onDone: ClosureDone? = nil, onCancel: ClosureCancel? = nil) {
        ...
    }

    public func showCorrelationPicker(title:String, correlationalJsonStr: String, selectedIndices: [Int], onDone: ClosureDone? = nil, onCancel: ClosureCancel? = nil) {
        ...
    }

    public func showCorrelationPicker(title:String, correlationalJsonFile: String, selectedItems: [String], onDone: ClosureDone? = nil, onCancel: ClosureCancel? = nil) {
        ...
    }

    public func showCorrelationPicker(title:String, correlationalJsonFile: String, selectedIndices: [Int], onDone: ClosureDone? = nil, onCancel: ClosureCancel? = nil) {
        ...
    }

    public func showGroupPicker(title:String, groupData: [[String]], selectedItems: [String], onDone: ClosureDone? = nil, onCancel: ClosureCancel? = nil) {
        ...
    }

    public func showGroupPicker(title:String, groupData: [[String]], selectedIndices: [Int], onDone: ClosureDone? = nil, onCancel: ClosureCancel? = nil) {
        ...
    }

    public func showDatePicker(title: String, initialDate: Date, onDone: ClosureDateDone? = nil, onCancel: ClosureCancel? = nil) {
        ...
    }
}

中国地区选择器

extension UIViewController {

    public func showPicker_ChineseRegionalism(title: String, selectedItems: [String], onDone: ClosureDone? = nil, onCancel: ClosureCancel? = nil) {
        ...
    }
}

使用PickerController

func onClicked_button1() {
        let data = [["1983", "1984", "1985"], ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]]
        showGroupPicker(title: "Hello", groupData: data, selectedItems: ["1984", "6月"], onDone: { [unowned self] (indices, items) in
            self.labelIndices.text = "indices -- \(indices)"
            self.labelItems.text = "items -- \(items)"
            }, onCancel: {
               self.labelIndices.text = "selected nothing"
                self.labelItems.text = "selected nothing"
        })
}

func onClicked_button2() {
        showPicker_ChineseRegionalism(title: "城市", selectedItems: ["江苏", "无锡"], onDone: { [unowned self] (indices, items) in
            self.labelIndices.text = "indices -- \(indices)"
            self.labelItems.text = "items -- \(items)"
            }, onCancel: {
                self.labelIndices.text = "selected nothing"
                self.labelItems.text = "selected nothing"
        })
}

func onClicked_button3() {
        showDatePicker(title: "时间", initialDate: Date(), onDone: { [unowned self] (date) in
            self.labelIndices.text = ""
            self.labelItems.text = "date -- \(date)"
            }, onCancel: {
                self.labelIndices.text = ""
                self.labelItems.text = "selected nothing"
        })
}

属性

  • height: CGFloat // PickerController中选择器的高度
  • animationDuration: TimeInterval // 选择器的动画持续时间
  • backgroundAlpha: CGFloat // PickerController的背景透明度

作者

xiongxiong, [email protected]

许可证

PickerController在MIT许可下可用。查看LICENSE文件了解更多信息。