Skip to content

loregr/McPicker-iOS

 
 

Repository files navigation

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 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"]]) {  (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) { (selections: [Int : String]) -> Void in
    if let name = selections[0] {
        self.label.text = name
    }
}

Customization

let customLabel = UILabel()
customLabel.textAlignment = .center
customLabel.textColor = .white
customLabel.font = UIFont(name:"American Typewriter", size: 30)!

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

let mcPicker = McPicker(data: data)
mcPicker.label = customLabel // Set your custom label
mcPicker.toolbarItemsFont = UIFont(name:"American Typewriter", size: 17)!
mcPicker.toolbarButtonsColor = .white
mcPicker.toolbarBarTintColor = .darkGray
mcPicker.pickerBackgroundColor = .gray

if let barButton = sender as? UIBarButtonItem {
    // Show as Popover
    //
    mcPicker.showAsPopover(fromViewController: self, barButtonItem: barButton) { (selections: [Int : String]) -> Void in
        if let prefix = selections[0], let name = selections[1] {
            self.label.text = "\(prefix) \(name)"
        }
    }
} else {
    // Show Normal
    //
    mcPicker.show { selections in
        if let prefix = selections[0], let name = selections[1] {
            self.label.text = "\(prefix) \(name)"
        }
    }
}

Requirements

  • iOS 8+
  • Swift 3+
  • Xcode 8

Installation

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

pod "McPicker"

Author

Kevin McGill, kevin@mcgilldevtech.com

License

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 95.9%
  • Ruby 4.1%