Latest 1.2.0
Homepage https://github.com/4074/UPicker
License MIT
Platforms ios 8.0
Frameworks UIKit
Authors

A picker widget written in Swift. Easy to use and set a custom style if you need.

Screenshot

screenshot

Installation

CocoaPods

# for swift 4
pod "UPicker", '~>1.1.0'

# fot swift 3
pod "UPicker", '~>1.0.1'

# for swift 2.3
pod 'UPicker', '~>0.1.1'

Manual

Download UPicker.swift and UPickerView.swift, and add them into your project.

Usage

Simple

class ViewController: UIViewController {
    let picker: UPicker?
    let data = [["First", "Second", "Third"]]
    let selected = [0]
    // ...

    func showPicker() {
        if picker == nil {
            picker = UPicker(frame: view.frame, didDisappear: { selected in
                if rows != selected {
                    print("select (rows[0])")
                }
            })
        }

        picker.pickerView.data = data
        picker.pickerView.selectedRows = selected
        picker?.present(self)
    }
}

Multiple Data

You could use multiple data.

//...
picker.pickerView.data = [["First", "Second", "Third"], ["Fourth", "Fifth"]]
picker.pickerView.selectedRows = [0, 0]
//...

Nested Data

In addition, nested data is available.

//...
picker.pickerView.data = [["Odd", "Even"]]
picker.pickerView.selectedRows = [0, 0]

// nested hierarchy
picker.pickerView.nestedHierarchy = 2
// nested data
picker.pickerView.nestedData = [
    "Odd": ["1", "3", "5", "7", "9"],
    "Even": ["2", "4", "6", "8"]
]

//...

Custom Style

UPicker is a child class of UIViewController. You can set custom transition when the date picker show.

UPicker.pickerView is a instance of UPickerView that is a child class of UIView. And You can get some view from its properties

  • pickerView: UIPickerView
  • barView: UIView
  • doneButton: UIButton
  • blankView: UIView

Therefor, You can do anything what you want with them.

For example:

// ...

// custom transition
picker.modalTransitionStyle = .FlipHorizontal

// custom button text
picker.pickerView.doneButton.setTitle("OK", forState: .Normal)

// custom picker view text color
picker.pickerView.textColor = UIColor.blueColor()

// ...

Latest podspec

{
    "name": "UPicker",
    "version": "1.2.0",
    "summary": "A picker widget written in Swift which is lightweight and extensible.",
    "homepage": "https://github.com/4074/UPicker",
    "license": "MIT",
    "authors": {
        "4074": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/4074/UPicker.git",
        "tag": "1.2.0"
    },
    "source_files": "UPicker/*.swift",
    "frameworks": [
        "UIKit"
    ]
}

Pin It on Pinterest

Share This