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

Overview

McPicker

Build Status Version License Platform

About

McPicker is a UIPickerView drop-in solution with animations that is rotation ready. The more string arrays you pass, the more picker components you'll get. You can set custom label or use the defaults. McPicker can be presented as a Popover on iPhone or iPad using showAsPopover, as an inputView using McTextField or use the default slide up and down style show.

showAsPopover can be used to display from a UIView or UIBarButtonItem. showAsPopover will always be presented as a Popover, even when used on an iPhone.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Short Syntax

  • Normal - (Slide up from bottom)
McPicker.show(data: [["Kevin", "Lauren", "Kibby", "Stella"]]) {  [weak self] (selections: [Int : String]) -> Void in
    if let name = selections[0] {
        self?.label.text = name
    }
}
  • As Popover
let data: [[String]] = [["Kevin", "Lauren", "Kibby", "Stella"]]
McPicker.showAsPopover(data: data, fromViewController: self, barButtonItem: sender) { [weak self] (selections: [Int : String]) -> Void in
    if let name = selections[0] {
        self?.label.text = name
    }
}
  • As an inputView via McTextField
@IBOutlet weak var mcTextField: McTextField!
override func viewDidLoad() {
    let data: [[String]] = [["Kevin", "Lauren", "Kibby", "Stella"]]
    let mcInputView = McPicker(data: data)
    mcInputView.backgroundColor = .gray
    mcInputView.backgroundColorAlpha = 0.25
    mcTextField.inputViewMcPicker = mcInputView

    mcTextField.doneHandler = { [weak mcTextField] (selections) in
        mcTextField?.text = selections[0]!
    }
    mcTextField.selectionChangedHandler = { [weak mcTextField] (selections, componentThatChanged) in
        mcTextField?.text = selections[componentThatChanged]!
    }
    mcTextField.cancelHandler = { [weak mcTextField] in
        mcTextField?.text = "Cancelled."
    }
    mcTextField.textFieldWillBeginEditingHandler = { [weak mcTextField] (selections) in
        if mcTextField?.text == "" {
            // Selections always default to the first value per component
            mcTextField?.text = selections[0]
        }
    }
}

Customization

let data: [[String]] = [
    ["Sir", "Mr", "Mrs", "Miss"],
    ["Kevin", "Lauren", "Kibby", "Stella"]
]
let mcPicker = McPicker(data: data)

let customLabel = UILabel()
customLabel.textAlignment = .center
customLabel.textColor = .white
customLabel.font = UIFont(name:"American Typewriter", size: 30)!
mcPicker.label = customLabel // Set your custom label

let fixedSpace = McPickerBarButtonItem.fixedSpace(width: 20.0)
let flexibleSpace = McPickerBarButtonItem.flexibleSpace()
let fireButton = McPickerBarButtonItem.done(mcPicker: mcPicker, title: "Fire!!!") // Set custom Text
let cancelButton = McPickerBarButtonItem.cancel(mcPicker: mcPicker, barButtonSystemItem: .cancel) // or system items
// Set custom toolbar items
mcPicker.setToolbarItems(items: [fixedSpace, cancelButton, flexibleSpace, fireButton, fixedSpace])

mcPicker.toolbarItemsFont = UIFont(name:"American Typewriter", size: 17)!
mcPicker.toolbarButtonsColor = .white
mcPicker.toolbarBarTintColor = .darkGray
mcPicker.backgroundColor = .gray
mcPicker.backgroundColorAlpha = 0.50
mcPicker.pickerBackgroundColor = .gray
mcPicker.pickerSelectRowsForComponents = [
    0: [3: true],
    1: [2: true] // [Component: [Row: isAnimated]
]

if let barButton = sender as? UIBarButtonItem {
    // Show as Popover
    //
    mcPicker.showAsPopover(fromViewController: self, barButtonItem: barButton) { [weak self] (selections: [Int : String]) -> Void in
        if let prefix = selections[0], let name = selections[1] {
            self?.label.text = "\(prefix) \(name)"
        }
    }
} else {
    // Show Normal
    //
    mcPicker.show(doneHandler: { [weak self] (selections: [Int : String]) -> Void in
        if let prefix = selections[0], let name = selections[1] {
            self?.label.text = "\(prefix) \(name)"
        }
    }, cancelHandler: {
        print("Canceled Styled Picker")
    }, selectionChangedHandler: { (selections: [Int:String], componentThatChanged: Int) -> Void  in
        let newSelection = selections[componentThatChanged] ?? "Failed to get new selection!"
        print("Component \(componentThatChanged) changed value to \(newSelection)")
    })
}
The selections

McPicker's doneHandler passes back selections: [Int : String] as an argument. This is as simple as [<Component Index>: <String of Selection>] from the data you've passed in.

Requirements

  • iOS 8+
  • Swift 5.2
  • Xcode 12

Note: Starting in 0.5.1 McPicker uses the Swift 4 Compiler. Ensure the correct compiler is set in your project.. If you'd like to use Swift 3 use version <=0.5.0.

Installation

McPicker is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "McPicker"

Xcode 12+ - Swift 5.2 Support

pod 'McPicker', '~> 3.0.0'

Swift 4.2 Support

For Swift 4.2 support, please use version 2.0.0.

pod 'McPicker', '~> 2.0.0'

Author

Kevin McGill, [email protected]

License

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

Comments
  • fix bug did selected row

    fix bug did selected row

    when i push a empty array to data in show method. i scroll in picker, i have a bug in method didselectedrow. this bug is index out of range. pickerSelection is empty and component =0 Please review for me!!

    opened by longvt96 10
  • Xcode 12 build errors

    Xcode 12 build errors

    Since updating and attempting to compile with Xcode 12 beta I've getting build errors from McPicker for these two functions public class func flexibleSpace() -> McPickerBarButtonItem public class func fixedSpace(width: CGFloat) -> McPickerBarButtonItem

    enhancement 
    opened by warpling 8
  • Is there any way using like 'didselect'??

    Is there any way using like 'didselect'??

    #I have two related picker view first picker : [ [Alphabet, Numbers] ] second picker : [ [a,b,c, ...] or [1,2,3, ...] ] if I select 'Alphabet' at first picker, second picker show [a,b,c, ...] and if select 'Numbers', show [1,2,3, ...]

    enhancement 
    opened by dev-yong 6
  • ToolbarItems Font For Other States

    ToolbarItems Font For Other States

    Hi , setting ToolbarItems Fonts is currently just set for the .normal state of the buttons and when you click it or longPress (hold) on it the font is changed to default for a moment or for the time you are holding it

    bug enhancement 
    opened by Mahan3340 6
  • The cancel handler is called even though the user is clicking on the done button.

    The cancel handler is called even though the user is clicking on the done button.

    self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(cancel))) The above line in the McPicker.setup() method is causing this issue.

    opened by sundeepdev 5
  • realodData() on picker how?

    realodData() on picker how?

    Hi, since this doesn't require your typical picker, how can I reload my data?

    I want to populate my data from firebase, but I can't update my array since there's no way to reloadData on an array.

    Thanks :)

    question more info required 
    opened by reecreateeduardo 4
  • toolbarItemsFont toolbarButtonsColor not working

    toolbarItemsFont toolbarButtonsColor not working

    Hi , mcPicker.toolbarItemsFont = UIFont(name: "W_koodak", size: 17)! this line is not working if its called before setting the toolbarItems and if its called after setting them its working fine and also its true for toolbarButtonsColor and maybe some more

    bug 
    opened by Mahan3340 4
  • Support Carthage

    Support Carthage

    Thank you for McPicker! McPicker looks to be exactly what I need, except that it doesn't support Carthage:

    $ carthage update --platform ios 
    *** Skipped building McPicker-iOS due to the error:
    Dependency "McPicker-iOS" has no shared framework schemes for any of the platforms: iOS
    

    I will experiment with adding support in my forked repo, and if successful, I will file a MR.

    opened by kenstir 3
  • Missing selected index

    Missing selected index

    Could be interesting to have the index of the selected item.

    I've done it locally directly in the McPicker.swift file here:

        public func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
            self.pickerSelection[component] = pickerData[component][row]
            self.pickerSelection[1] = String(row)
        }
    

    I then get the result in the done Handler:

                mcPicker.show { (selections: [Int : String]) -> Void in
                    self.mySelection = myArray[Int(selections[1]!)!]
                }
    
    question 
    opened by YSDC 3
  • Custom ToolbarItems

    Custom ToolbarItems

    Hi , please provide some method to change default ToolbarItems text (done,cancel) and setToolBarItems method that gets and array of buttons is not working properly in viewing them have you checked them ? how to add two custom toolbarItems like "done" and "cancel" but with custom styles ?

    opened by Mahan3340 2
  • Is there a way to get the selected row or index, besides the text

    Is there a way to get the selected row or index, besides the text

    I was trying to use this to choose from a list of [id:String], but since it only accepts [[String]], I created two lists one of [id] and one of [[String]], I want to know if I can get the selected row (index) in order to get the id from the other list, thanks. Note: I have repeating strings so IndexOf will not help

    opened by jcifuentes91 1
  • trouble with AppCenter

    trouble with AppCenter

    Hi,

    I got this issue while trying to build my app on AppCenter

    CompileSwift normal armv7 (in target 'McPicker' from project 'Pods') cd /Users/runner/work/1/s/YourFut/Pods /Applications/Xcode_11.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -emit-bc /Users/runner/work/1/s/YourFut/Pods/McPicker/McPicker/Classes/McPicker.swift /Users/runner/work/1/s/YourFut/Pods/McPicker/McPicker/Classes/McPickerBarButtonItem.swift /Users/runner/work/1/s/YourFut/Pods/McPicker/McPicker/Classes/McPickerPopoverViewController.swift /Users/runner/work/1/s/YourFut/Pods/McPicker/McPicker/Classes/McTextField.swift -emit-module-path /Users/runner/Library/Developer/Xcode/DerivedData/YourFut-bcgsjxzsmxluocadjionpbjzwutd/Build/Intermediates.noindex/ArchiveIntermediates/YourFut/IntermediateBuildFilesPath/Pods.build/Release-iphoneos/McPicker.build/Objects-normal/armv7/McPicker.swiftmodule -emit-module-doc-path /Users/runner/Library/Developer/Xcode/DerivedData/YourFut-bcgsjxzsmxluocadjionpbjzwutd/Build/Intermediates.noindex/ArchiveIntermediates/YourFut/IntermediateBuildFilesPath/Pods.build/Release-iphoneos/McPicker.build/Objects-normal/armv7/McPicker.swiftdoc -serialize-... /Users/runner/work/1/s/YourFut/Pods/McPicker/McPicker/Classes/McPickerBarButtonItem.swift:61:32: error: method does not override any method from its superclass public override class func flexibleSpace() -> Self { ~~~~~~~~ ^

    xCode is fine but the issue happen with AppCenter only. :(

    opened by dohoangminhquan 1
  • Use of unresolved identifier 'mcTextField'

    Use of unresolved identifier 'mcTextField'

    I copied handler from example : self.txt.doneHandler = { [weak mcTextField] (selections) in mcTextField?.text = selections[0]! }

    but I got error Use of unresolved identifier 'mcTextField'

    opened by Kendokai 0
Releases(2.0.1)
Owner
Kevin McGill
Kevin McGill
LocationPicker - A ready for use and fully customizable location picker for your app

LocationPicker A ready for use and fully customizable location picker for your app. Features Installation Cocoapods Carthage Swift Package Manager Qui

Zhuoran 397 Nov 16, 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
Elegant manager to easily deal with UIPickerView

PickL PickL is an elegant manager to easily deal with UIPickerView. You don't have to implement a logic for UIPickerViewDataSource and UIPickerViewDel

Rosberry 5 Jun 24, 2021
A drop in single image picker.

PHSingleImagePicker A low memory, single image picker wrapper that provide a significant smaller file size while also preserve high image quality. Int

Phanith NY 0 Nov 6, 2021
FYPhoto is a photo/video picker and image browser library for iOS written in pure Swift. It is feature-rich and highly customizable to match your App's requirements.

FYPhoto is a photo/video picker and image browser library for iOS written in pure Swift. It is feature-rich and highly customizable to match your App's requirements.

null 10 Dec 11, 2022
A simple, customizable view for efficiently collecting country information in iOS apps.

CountryPickerView CountryPickerView is a simple, customizable view for selecting countries in iOS apps. You can clone/download the repository and run

Kizito Nwose 459 Dec 27, 2022
A fully customizable iOS Horizontal PickerView library, written in pure swift

ADDatePicker is Horizontal Date Picker Library written in Swift Requirements Communication Installation Usage Demo Customization Credits License Requi

Abhishek Dave 166 Dec 21, 2022
A simple yet customizable horizontal and vertical picker view

WheelPicker A simple yet customizable horizontal and vertical picker view Features Vertical or Horizontal picker Image or Text data Configure UILabel

Mind Studios 74 Sep 26, 2022
Highly customizable drop-in solution for introduction views.

EAIntroView - simple iOS Introductions This is highly customizable drop-in solution for introduction views. Some features (remember, most features are

Evgeny Aleksandrov 3.8k Dec 17, 2022
A Swift based reimplementation of the Apple HUD (Volume, Ringer, Rotation,…) for iOS 8.

A Swift based reimplementation of the Apple HUD (Volume, Ringer, Rotation,…) for iOS 8 and up. Features Official iOS 8 blur effect via UIVisualEffects

Philip Kluz 3.7k Jan 9, 2023
🔸 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
A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!

ver 2.0 NB! Breaking changes in 2.0 - due to a lot of requests EasyAnimation does NOT automatically install itself when imported. You need to enable i

Marin Todorov 3k Dec 27, 2022
TestKit has been upgraded to a full solution for implementing Behavior-Driven Development (BDD) in Swift iOS apps.

The easiest way to implement full BDD in your Swift iOS projects! Use plain English specs (Gherkin) to drive tests that include both UI automation and interacting with application data & state.

Daniel Hall 11 Sep 14, 2022
The most powerful Event-Driven Observer Pattern solution the Swift language has ever seen!

Event-Driven Swift Decoupling of discrete units of code contributes massively to the long-term maintainability of your project(s). While Observer Patt

Flowduino 4 Nov 14, 2022
MacOS Serial solution (Observable & Event-Driven) to make integration of Serial peripherals trivial

SerialSwift SerialSwift makes communicating with your Serial Peripherals on MacOS trivial. Better still, SerialSwift is designed to be fundamnetally O

Flowduino 2 Sep 9, 2022
[iOS] Easy, customizable notifications displayed on top of the statusbar. With progress and activity. iPhone X ready.

JDStatusBarNotification Show messages on top of the status bar. Customizable colors, font and animation. Supports progress display and can show an act

M Emrich 3.8k Dec 27, 2022
A ready for use and fully customizable location picker for your app

LocationPicker A ready for use and fully customizable location picker for your app. Features Installation Cocoapods Carthage Swift Package Manager Qui

Zhuoran 397 Nov 16, 2022
LocationPicker - A ready for use and fully customizable location picker for your app

LocationPicker A ready for use and fully customizable location picker for your app. Features Installation Cocoapods Carthage Swift Package Manager Qui

Zhuoran 397 Nov 16, 2022