GithubHelp home page GithubHelp logo

mdabbagh88 / actionsheetpicker-3.0 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from skywinder/actionsheetpicker-3.0

0.0 1.0 0.0 4.03 MB

Quickly reproduce the dropdown UIPickerView / ActionSheet functionality on iOS.

Home Page: http://skywinder.github.io/ActionSheetPicker-3.0

License: BSD 3-Clause "New" or "Revised" License

Ruby 0.48% Objective-C 94.83% C++ 0.74% Swift 3.96%

actionsheetpicker-3.0's Introduction

Version Build Status License Platform Issues

ActionSheetPicker-3.0

Since the Tim's repo is not support iOS 7+, I forked from his repo and implement iOS 7-8 support, and also bunch of UI fixes, crash-fixes and different customisation abilities.

New updates will be added only in this repo.

Please welcome: ActionSheetPicker-3.0!

pod 'ActionSheetPicker-3.0', '~> 1.3.9' (iOS 6-7-8 compatible!)

Improvements more than welcome - they are kindly requested :)

Regards, Petr Korolev

##ActionSheetPicker = UIPickerView + UIActionSheet ##

ActionSheetLocalePicker

Well, that's how it started. Now, the following is more accurate:

  • iPhone/iPod ActionSheetPicker = ActionSheetPicker = A Picker + UIActionSheet
  • iPad ActionSheetPicker = A Picker + UIPopoverController

Overview

Easily present an ActionSheet with a PickerView, allowing user to select from a number of immutable options.

Benefits

  • Spawn pickers with convenience function - delegate or reference not required. Just provide a target/action callback.
  • Add buttons to UIToolbar for quick selection (see ActionSheetDatePicker below)
  • Delegate protocol available for more control
  • Universal (iPhone/iPod/iPad)

QuickStart

There are 4 distinct picker view options: ActionSheetStringPicker, ActionSheetDistancePicker, ActionSheetDatePicker, and ActionSheetCustomPicker. We'll focus here on how to use the ActionSheetStringPicker since it's most likely the one you want to use.

Basic Usage

// Inside a IBAction method:

// Create an array of strings you want to show in the picker:
NSArray *colors = [NSArray arrayWithObjects:@"Red", @"Green", @"Blue", @"Orange", nil];

[ActionSheetStringPicker showPickerWithTitle:@"Select a Color"
                                        rows:colors
                            initialSelection:0
                                   doneBlock:nil
                                 cancelBlock:nil
                                      origin:sender];

But you probably want to know when something happens, huh?

// Inside a IBAction method:

// Create an array of strings you want to show in the picker:
NSArray *colors = [NSArray arrayWithObjects:@"Red", @"Green", @"Blue", @"Orange", nil];

[ActionSheetStringPicker showPickerWithTitle:@"Select a Color"
                                        rows:colors
                            initialSelection:0
                                   doneBlock:^(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue) {
                                      NSLog(@"Picker: %@", picker);
                                      NSLog(@"Selected Index: %@", selectedIndex);
                                      NSLog(@"Selected Value: %@", selectedValue);
                                    }
                                 cancelBlock:^(ActionSheetStringPicker *picker) {
                                      NSLog(@"Block Picker Canceled");
                                    }
                                      origin:sender];
// You can also use self.view if you don't have a sender

ActionSheetCustomPicker Customisation

ActionSheetCustomPicker provides the following delegate function that can be used for customization:

- (void)actionSheetPicker:(AbstractActionSheetPicker *)actionSheetPicker configurePickerView:(UIPickerView *)pickerView;

This method is called right before actionSheetPicker is presented and it can be used to customize the appearance and properties of the actionSheetPicker and the pickerView associated with it.

Want custom buttons view? Ok!

Example with custom text in Done button:

    ActionSheetStringPicker *picker = [[ActionSheetStringPicker alloc] initWithTitle:@"Select a Block" rows:colors initialSelection:0 doneBlock:done cancelBlock:cancel origin:sender];
    [picker setDoneButton:[[UIBarButtonItem alloc] initWithTitle:@"My Text"  style:UIBarButtonItemStylePlain target:nil action:nil]];
    [picker showActionSheetPicker];

Example with custom button for cancel button:

    ActionSheetStringPicker *picker = [[ActionSheetStringPicker alloc] initWithTitle:@"Select a Block" rows:colors initialSelection:0 doneBlock:done cancelBlock:cancel origin:sender];
    UIButton *cancelButton =  [UIButton buttonWithType:UIButtonTypeCustom];
    [cancelButton setImage:[UIImage imageNamed:@"cancel.png"] forState:UIControlStateNormal];
    [cancelButton setFrame:CGRectMake(0, 0, 32, 32)];
    [picker setCancelButton:[[UIBarButtonItem alloc] initWithCustomView:cancelButton]];
    [picker showActionSheetPicker];

What about custom buttons callbacks? Let's check it out:

 // Inside a IBAction method:

 // Create an array of strings you want to show in the picker:
NSArray *colors = [NSArray arrayWithObjects:@"Red", @"Green", @"Blue", @"Orange", nil];
 
 //Create your picker:
ActionSheetStringPicker *colorPicker = [[ActionSheetStringPicker alloc] initWithTitle:@"Select a color"
                                                                                 rows:colors
                                                                     initialSelection:0
                                                                               target:nil
                                                                        successAction:nil
                                                                         cancelAction:nil
                                                                               origin:sender];
 
 //You can pass your picker a value on custom button being pressed:
[colorPicker addCustomButtonWithTitle:@"Value" value:@([colors indexOfObject:colors.lastObject])];
 
 //Or you can pass it custom block:
[colorPicker addCustomButtonWithTitle:@"Block" actionBlock:^{
    NSLog(@"Custom block invoked");
}];

 //If you prefer to send selectors rather than blocks you can use this method:
[colorPicker addCustomButtonWithTitle:@"Selector" target:self selector:@selector(awesomeSelector)];

##Installation##

  • The most easiest way is through Cocoapods. Just add to your Podfile string: pod 'ActionSheetPicker-3.0'

  • The "old school" way is manually add to your project all from Pickers folder and import necessary headers.

Example Projects##

For iOS 8 (Objective-C + Swift):

open Example.xcworkspace

Here is 4 projects:

  • CoreActionSheetPicker - all picker files combined in one Framework. (available since iOS 8)
  • ActionSheetPicker - modern and descriptive Obj-C project with many examples.
  • Swift-Example - example, written on Swift. (only with basic 3 Pickers examples, for all examples please run ActionSheetPicker project)
  • ActionSheetPicker-iOS6-7 - iOS 6 and 7 comparable project. or to run only this project open Example-for-and-6/ActionSheetPicker.xcodeproj

Screenshots

ActionSheetPicker ActionSheetDatePicker ActionSheetDatePicker CustomButtons iPad Support

If you are using ActionSheetPicker-3.0 in your app or know of an app that uses it, please add it to [this] (https://github.com/skywinder/ActionSheetPicker-3.0/wiki/Apps-using-ActionSheetPicker-3.0) list.

Maintainer and Contributor

  • Petr Korolev (update to iOS 7 and iOS 8, implementing new pickers, community support)

Credits

Contributing

  1. Create an issue to discuss about your idea
  2. Fork it (https://github.com/skywinder/ActionSheetPicker-3.0/fork)
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

Bug reports, feature requests, patches, well-wishes, and rap demo tapes are always welcome.

Analytics

Bitdeli Badge

actionsheetpicker-3.0's People

Contributors

0xmark avatar atm-abe avatar brettg avatar delackner avatar ecordell avatar elwerene avatar emmanuelay avatar grgcombs avatar jack-s avatar jeffreyjackson avatar jklp avatar jkrzemie avatar johnnyg avatar jparise avatar markrickert avatar mau04 avatar mgmart avatar michalciolek avatar nebiros avatar nimuzak avatar nowsprinting avatar ronakjangir47 avatar skywinder avatar stupergenius avatar timcinel avatar tomaskraina avatar tonsilver avatar velga avatar venj avatar vuraltuna avatar

Watchers

 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.