Giter Club home page Giter Club logo

swiftpickers's Introduction

SwiftPickers

Language Platform License Issues

Overview

This is a Swift port of ActionSheetPicker-3.0. However, this project contains some functionality which is different from the original component and certain design decisions have been taken to keep things simpler for this version.

The SwiftPicker components can be used in one of two ways - you can either invoke the picker directly from code:

swift-pickers

Or, you can use the easy to use picker buttons which can be added to a storyboard or instantiated via. The buttons require a couple of lines to set up the picker and then the button will handle the rest:

picker-buttons

As you will note above, each button displays the current selection value as its title.

Installation

You can use the SwiftPicker components two ways:

Pickers

The basic picker components of SwiftPickers are not visual components that can be added via Interface Builder. Instead, you have to create them via code.

There are several different picker components depending on the type of value you want to display but one of the most basic picker components is the StringSwiftPicker, which allows you to pick a value from a list of string values passed to the picker.

Instantiating and invoking a StringSwiftPicker is as simple as:

let data = ["Red", "Blue", "Green", "Yellow"]
let p = StringSwiftPicker(title:"Colours", data:data, selected:0, done:{(pv, index, value) in
	println("Selected item: \(index) with value: \(value)")
}, cancel:{(pv) in
	println("Cancelled selection")
})
p.showPicker(self)

Note: Till the documentation is updated to reflect all functionality, refer to the ViewController.swift file in the included sample project for all the different ways that the various picker components can be invoked via code.

Button Pickers

The button picker components are the visual components in the SwiftPicker collection. They can be added to your application in two different ways:

Via Interface Builder

  • Add a standard UIButton instance to your view on your storyboard.
  • Change the class for the button to the SwiftPicker button class of your choice (ex: StringPickerButton, DatePickerButton etc.)
  • Set up an outlet for the button in your view controller and connect the button to the outlet.
  • Set up any configuration values for the button that can't be set via the storyboard in your code. You always have to pass a view controller instance to the button but the other configuration values vary depending on the type of picker button.

Via Code

  • Create an instance of a SwiftPicker button in your view controller:
let data = ["Red", "Blue", "Green", "Yellow"]
let btn = StringPickerButton(vc:self, title:"Colour Picker", data:data, selected:1, picked:{(val, ndx) in
	println("Picked the value: \(val) with index: \(ndx)")
})
  • Add the button to your view and you're done :)

Note: Till the documentation is updated to reflect all functionality, refer to the ButtonsViewController.swift file and the storyboard in the included sample project for all the different ways that the various button pickers can be used in a project.

Credits

  • The inspiration for SwiftPickers, ActionSheetPicker, was originally created by Tim Cinel (@TimCinel)
  • The version of the code that I used as the basis for this version of SwiftPickers was created by Petr Korolev

Questions?

swiftpickers's People

Contributors

fahimf avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.