Latest0.2.5
Homepagehttps://github.com/ChernyshenkoTaras/TCPickerView
LicenseMIT
Platformsios 9.0
Authors

Picker view popup with multiply rows selection written in Swift.

TCPickerView
TCPickerView
TCPickerView

Requirements

TimeIntervalPicker works on iOS 9 and higher. It depends on the following Apple frameworks, which should already be included with most Xcode templates:

  • Foundation
  • UIKit

Installation

CocoaPods

You can use CocoaPods to install TimeIntervalPicker by adding it to your Podfile:

platform :ios, '9.0'
use_frameworks!
pod 'TCPickerView'

Manually

  1. Download and drop Classes and Assets folder in your project.
  2. Congratulations!

Example

import UIKit
import TCPickerView

class ViewController: UIViewController {

    @IBAction private func showButtonPressed(button: UIButton) {
        var picker: TCPickerViewInput = TCPickerView()
        picker.title = "Cars"
        let cars = [
            "Chevrolet Bolt EV",
            "Subaru WRX",
            "Porsche Panamera",
            "BMW 330e",
            "Chevrolet Volt",
            "Ford C-Max Hybrid",
            "Ford Focus"
        ]
        let values = cars.map { TCPickerView.Value(title: $0) }
        picker.values = values
        picker.delegate = self
        picker.selection = .single
        picker.completion = { (selectedIndexes) in
            for i in selectedIndexes {
                print(values[i].title)
            }
        }
        picker.show()
    }
}

If you want to set pre-selected values: TCPickerView.Value(title: "Chevrolet Bolt EV", isChecked: true)

Picker supports multiply, single and none row selection. You can set desired behavior by setting selection property of TCPickerView to the appropriate value.

Tracking user actions

TCPickerViewOutput allows you track what item was selected. Implament this method in your controller and assign delegate property
to this controller.

public protocol TCPickerViewOutput: class {
    func pickerView(_ pickerView: TCPickerView, didSelectRowAtIndex index: Int)
}

You can request new method if you need it. I’m open to discuss

UI customization

Create a class that conform to TCPickerViewThemeType protocol and adjust UI layout or use one of the existing themes:

  • TCPickerViewDefaultTheme
  • TCPickerViewLightTheme
  • TCPickerViewDarkTheme

Use them as reference for creation you own awesome design.

You can change next properties:

var doneText: String { get }
var closeText: String { get }

var backgroundColor: UIColor { get }
var titleColor: UIColor { get }
var doneTextColor: UIColor { get }
var closeTextColor: UIColor { get }
var headerBackgroundColor: UIColor { get }
var doneBackgroundColor: UIColor { get }
var closeBackgroundColor: UIColor { get }
var separatorColor: UIColor { get }

var buttonsFont: UIFont { get }
var titleFont: UIFont { get }

var rowHeight: CGFloat { get }
var headerHeight: CGFloat { get }
var cornerRadius: CGFloat { get }

Use your own cells

  • desing your cell in .xib or code
  • conform your cell to TCPickerCellType protocol
  • register cell in picker by using one of next methods
    func register(_ nib: UINib?, forCellReuseIdentifier identifier: String)
    func register(_ cellClass: Swift.AnyClass?, forCellReuseIdentifier identifier: String)
  • implement TCPickerViewOutput protocol in your view controller
  • dequeue your cell in func pickerView(_ pickerView: TCPickerViewInput, cellForRowAt indexPath: IndexPath) -> (UITableViewCell & TCPickerCellType)? method by calling func dequeueReusableCell(withIdentifier identifier: String, for indexPath: IndexPath) -> UITableViewCell & TCPickerCellType
  • for more details have a look into LightViewController file in a example project.

Contributing to this project

If you have feature requests or bug reports, feel free to help out by sending pull requests or create issues.

License

This code is distributed under the terms and conditions of the MIT license.

Latest podspec

{
    "name": "TCPickerView",
    "version": "0.2.5",
    "summary": "Picker view popup with multiply rows selection written in Swift",
    "description": "Picker view popup with ability to select multiply rows written in Swift",
    "homepage": "https://github.com/ChernyshenkoTaras/TCPickerView",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Taras Chernyshenko": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ChernyshenkoTaras/TCPickerView.git",
        "tag": "0.2.5"
    },
    "social_media_url": "https://twitter.com/@t_chernyshenko",
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "TCPickerView/Source/Classes/**/*",
    "ios": {
        "resource_bundles": {
            "TCPickerView": [
                "TCPickerView/Source/Resources/**/*.{xcassets}"
            ]
        }
    }
}

Pin It on Pinterest

Share This