Elegant manager to easily deal with UIPickerView

Overview

PickL

platforms Swift Version Carthage Compatible Version PRs Welcome

PickL is an elegant manager to easily deal with UIPickerView. You don't have to implement a logic for UIPickerViewDataSource and UIPickerViewDelegate by yourself anymore, it's already done under the hood.

Usage ๐Ÿš€

PickL is the main object, it frees you from a directly work with delegate and datasource.

PickL<StringAdaptor>(pickerView: pickerView)

Due to some UIPickerView restrictions, you can't work with view and string representable items simultaneously in one picker view. So you have to point out an adapter: StringAdaptor or ViewAdaptor ๐Ÿ”Œ .

Component items / row items

A bit of terminology - image below explains everything that you need to understand the future explanations.

๐Ÿ”ฌ Let's dive in:

  1. You have a few ways of creating a row item.

    String representable. There's an extension for NSAttributedString and String for convenient row item initializing:

    let rowItem = NSAttributedString(string: "Nikita", attributes: [NSAttributedStringKey.foregroundColor: UIColor.red])
    
    let rowItems: [RowStringItemProtocol] = ["Nikita", "Artem"]

    or a directly inheritance from RowStringItemProtocol:

    /// In this case you have a `didSelectHandler`.
    let rowItem1 = RowStringItem(title: "Nikita")
    let rowItem2 = RowAttributedStringItem(attributedTitle: NSAttributedString(string: "Artem"))
    class CustomRowItem: RowStringItemProtocol {
        let name: String
    
        init(name: String) {
            self.name = name
        }
        
        func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
            return name
        }
    }

    And the similar approach for view representable:

    let rowItem1 = UIView(title: "Nikita")
    let rowItem2 = UIView(title: "Artem")
    class CustomRowItem: RowViewItemProtocol {
        
        func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
            return UIView() /// return custom view
        }
    }
  2. Then using these row items create a component item.

    let componentItem = ComponentItem<StringAdaptor>(rowItems: [rowItem1, rowItem2])
  3. And finally you need to install this component.

    let pickL = PickL<StringAdaptor>(pickerView: pickerView)
    pickL.components = [componentItem]

A bit more about component item.

Component items provides a plenty of selection approaches:

  • selectRow(_ row: Int, animated: Bool)
  • selectNextRow(animated: Bool, checkIndexOutOfRange: Bool, isLoopEnabled: Bool)
  • selectPreviousRow(animated: Bool, checkIndexOutOfRange: Bool, isLoopEnabled: Bool)
  • selectFirstRow(animated: Bool)
  • selectLastRow(animated: Bool)

Detecting row selection ๐Ÿ‘€

User has a few ways for detecting a row selection:

  • Each row item that is inherited from RowStringItem, RowAttributedStringItem or directly from RowItem has a callback with passed row index and component index - useful when you want to monitor a selection for some specific item:

     rowItem.didSelectHandler = { rowIndex, componentIndex in
     	// Place for advertisement ๐Ÿ™ˆ
     }
  • If you don't want to follow the changes for some specific row item, it's also possible to observe a row selection directly from a component:

     componentItem.didSelectRowHandler = { componentItem, rowIndex, rowItem in
     	print("๐Ÿ’ƒ ๐Ÿ’ƒ ๐Ÿ’ƒ")
     }

    or directly get a selected row item: componentItem.selectedRowItem

  • To the last, user has the ability to detect all row selection in each component just in one callback:

     pickL.selectedRowsHandler { rowIndex1, rowIndex2, ... in
     	print("\(rowIndex1), \(rowIndex2)")
     }

    or use an array of all selected rows:

     print(pickL.selectedRows) // [0, 1]

    ๐Ÿ™‹โ€โ™‚๏ธ Note: This callback has up to 7 passed parameters (row indexes).

    Even if you have more than 7 component items, there is a general solution:

     pickL.selectedRowsArrayHandler { selectedRows in
         print(selectedRows)
     }

Installation

Depo

Depo is a universal dependency manager that combines Carthage, SPM and CocoaPods and provides common user interface to all of them.

To install PickL via Carthage using Depo you need to add this to your Depofile:

carts:
  - kind: github
    identifier: rosberry/PickL
To install PickL via CocoaPods Add this to your Depofile:
pods:
  - name: PickL

Carthage

Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add the framework to your project.

github "rosberry/PickL"

CocoaPods

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

platform :ios, '12.0'
use_frameworks!
pod 'PickL'

Manually

Drag Sources folder from last release into your project.

Authors

About

This project is owned and maintained by Rosberry. We build mobile apps for users worldwide ๐ŸŒ .

Check out our open source projects, read our blog or give us a high-five on ๐Ÿฆ @rosberryapps.

License

PickL is available under the MIT license. See the LICENSE file for more info.

You might also like...
๐Ÿ”ธ A customizable alternative to UIPickerView in Swift.
๐Ÿ”ธ A customizable alternative to UIPickerView in Swift.

PickerView PickerView is an easy to use and customize alternative to UIPickerView written in Swift. It was developed to provide a highly customizable

McPicker is a customizable, closure driven UIPickerView drop-in solution with animations that is rotation ready.
McPicker is a customizable, closure driven UIPickerView drop-in solution with animations that is rotation ready.

McPicker About McPicker is a UIPickerView drop-in solution with animations that is rotation ready. The more string arrays you pass, the more picker co

This is an iOS control for selecting something using UIPickerView in an UIAlertController like manner
This is an iOS control for selecting something using UIPickerView in an UIAlertController like manner

RMPickerViewController This framework allows you to pick something with a picker presented as an action sheet. In addition, it allows you to add actio

TextField with DropDown support using UIPickerView
TextField with DropDown support using UIPickerView

IQDropDownTextField TextField with DropDown support using UIPickerView Installing Install using cocoapods. Add in your Podfile: pod 'IQDropDownTextFie

TryCustomDatePicker - Customize UIDatePicker via UIPickerView
TryCustomDatePicker - Customize UIDatePicker via UIPickerView

TryCustomDatePicker This is just test code Customize UIDatePicker via UIPickerVi

Task-Manager - Task Manager App With Swift
Task-Manager - Task Manager App With Swift

Task-Manager It's typical task manager where user can assign the importance, def

SwiftyJSON makes it easy to deal with JSON data in Swift.

SwiftyJSON SwiftyJSON makes it easy to deal with JSON data in Swift. Platform Build Status *OS Linux Why is the typical JSON handling in Swift NOT goo

The most swifty way to deal with XML data in swift 5.

SwiftyXML SwiftyXML use most swifty way to deal with XML data. Features Infinity subscript dynamicMemberLookup Support (use $ started string to subscr

Pigeon is a SwiftUI and UIKit library that relies on Combine to deal with asynchronous data.

Pigeon ๐Ÿฆ Introduction Pigeon is a SwiftUI and UIKit library that relies on Combine to deal with asynchronous data. It is heavily inspired by React Qu

The better way to deal with JSON in Objective-C (inspired by SwiftyJSON)

NSTEasyJSON Inpired by SwiftyJSON. NSTEasyJSON makes it easy to deal with JSON data in Objective-C. Why is the typical JSON handling in Objective-C NO

A sensible way to deal with XML & HTML for iOS & macOS

Ono (ๆ–ง) Foundation lacks a convenient, cross-platform way to work with HTML and XML. NSXMLParser is an event-driven, SAX-style API that can be cumbers

๐Ÿš€ Create XCFrameworks with ease! A Command Line Tool to create XCFramework for multiple platforms at one shot! The better way to deal with XCFrameworks for iOS, Mac Catalyst, tvOS, macOS, and watchOS.
๐Ÿš€ Create XCFrameworks with ease! A Command Line Tool to create XCFramework for multiple platforms at one shot! The better way to deal with XCFrameworks for iOS, Mac Catalyst, tvOS, macOS, and watchOS.

Surmagic ๐Ÿš€ Create XCFramework with ease! A Command Line Tool to create XCFramework for multiple platforms at one shot! The better way to deal with XC

A wrapper to make it really easy to deal with iOS, macOS, watchOS and Linux Keychain and store your user's credentials securely.

A wrapper (written only in Swift) to make it really easy to deal with iOS, macOS, watchOS and Linux Keychain and store your user's credentials securely.

Deal with query items, HTTP headers, request body and more in an easy, declarative way

Reusable system for complex URL requests with Swift. Deal with query items, HTTP headers, request body and more in an easy, declarative way. Check out our engineering blog to learn more!

VKPinCodeView is simple and elegant UI component for input PIN. You can easily customise appearance and get auto fill (OTP) iOS 12 feature right from the box.
VKPinCodeView is simple and elegant UI component for input PIN. You can easily customise appearance and get auto fill (OTP) iOS 12 feature right from the box.

Features Variable PIN length Underline, border and custom styles The error status with / without shake animation Resetting the error status manually,

A Location Manager for easily implementing location services & geofencing in iOS. Ready for iOS 11.
A Location Manager for easily implementing location services & geofencing in iOS. Ready for iOS 11.

A Location Manager for easily implementing location services & geofencing in iOS, written in Objective-C. Ready for iOS 11. Features Get current/conti

Gravity is a simple Swift Package Manager to add gravity to UI objects easily.
Gravity is a simple Swift Package Manager to add gravity to UI objects easily.

Gravity -- Gravity is a simple Swift Package to add gravity to UI objects easily. -- How to use: Add a new Swift Package from XCode and paste the url

Install Agora Audio SDK for macOS easily with Swift Package Manager
Install Agora Audio SDK for macOS easily with Swift Package Manager

Agora Swift Package Manager Install Agora Audio SDK for macOS easily with Swift Package Manager. Click here for full documentation. Installation Add t

Tip-Calculation- - A program for calculate the tip. You can easily calculate it and you can split money easily
Tip-Calculation- - A program for calculate the tip. You can easily calculate it and you can split money easily

Tip-Calculation- It is a program for calculate the tip. You can easily calculate

Releases(1.0.0)
Owner
Rosberry
Rosberry
๐Ÿ”ธ A customizable alternative to UIPickerView in Swift.

PickerView PickerView is an easy to use and customize alternative to UIPickerView written in Swift. It was developed to provide a highly customizable

Filipe Alvarenga 488 Dec 21, 2022
McPicker is a customizable, closure driven UIPickerView drop-in solution with animations that is rotation ready.

McPicker About McPicker is a UIPickerView drop-in solution with animations that is rotation ready. The more string arrays you pass, the more picker co

Kevin McGill 207 Dec 13, 2022
Elegant and Easy-to-Use iOS Swift Date Picker

D2PDatePicker Example To run the example project, clone the repo, and run pod install from the Example directory first. Example Code: Programmatical I

Pradheep Rajendirane 292 Nov 6, 2022
A modern download manager based on NSURLSession to deal with asynchronous downloading, management and persistence of multiple files.

TWRDownloadManager TWRDownloadManager A modern download manager for iOS (Objective C) based on NSURLSession to deal with asynchronous downloading, man

Michelangelo Chasseur 407 Nov 19, 2022
SwiftySound is a simple library that lets you deal with Swift sounds easily

SwiftySound Overview SwiftySound is a simple library that lets you deal with Swift sounds easily. Static methods Sound.play(file: "dog.wav") Sound.pla

Adam Cichy 1.1k Dec 17, 2022
PySwiftyRegex - Easily deal with Regex in Swift in a Pythonic way

PySwiftyRegex Easily deal with Regex in Swift in a Pythonic way.

Ce Zheng 232 Oct 12, 2022
A Swift micro-framework to easily deal with weak references to self inside closures

WeakableSelf Context Closures are one of Swift must-have features, and Swift developers are aware of how tricky they can be when they capture the refe

Vincent Pradeilles 72 Sep 1, 2022
A Swift micro-framework to easily deal with weak references to self inside closures

WeakableSelf Context Closures are one of Swift must-have features, and Swift developers are aware of how tricky they can be when they capture the refe

Vincent Pradeilles 72 Sep 1, 2022
Easily deal with Regex in Swift in a Pythonic way

PySwiftyRegex Easily deal with Regex in Swift in a Pythonic way. ็ฎ€ไฝ“ไธญๆ–‡ ๆ—ฅๆœฌ่ชž ํ•œ๊ตญ์–ด This is Easy import PySwiftyRegex if let m = re.search("[Tt]his is (.*?

Ce Zheng 232 Oct 12, 2022
Quickly reproduce the dropdown UIPickerView / ActionSheet functionality on iOS.

ActionSheetPicker-3.0 Important update Now I fixed most of the things and merge PR' (thanks to ). I did much work to support this library from iOS 5.

Petr Korolev 3.4k Dec 21, 2022