Skip to content

A custom view component that presents a UIPickerView with a simple list of options, along with a toolbar for Done/Cancel and a faded backdrop view.

License

Notifications You must be signed in to change notification settings

shunding/BSModalPickerView

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BSModalPickerView

BSModalPickerView

A custom view component that presents a UIPickerView with a simple list of options, along with a toolbar for Done/Cancel and an optional faded backdrop view.

BSModalDatePickerView

A custom view component that presents a UIDatePicker with a toolbar for Done/Cancel, and an optional Today button.

Usage

Usage is easy:

Add the dependency to your Podfile:

platform :ios
pod 'BSModalPickerView'
...

Run pod install to install the dependencies.

Next, import the header file wherever you want to use the picker:

#import <BSModalPickerView/BSModalPickerView.h> // or <BSModalPickerView/BSModalDatePickerView.h>

Finally, present the picker when necessary (say on a button touch handler):

self.values = @[ @"Apples", @"Bananas", @"Grapes" ];
BSModalPickerView *picker = [[BSModalPickerView alloc] initWithValues:self.values];
[picker presentInView:self.view withBlock:^(BOOL madeChoice) {
  if (madeChoice) {
    NSLog(@"You chose index %d, which was the value %@", 
      picker.selectedIndex,
      picker.selectedValue);
  } else {
    NSLog(@"You cancelled the picker");
  }
}];
BSModalDatePickerView *datePicker = [[BSModalDatePickerView alloc] initWithDate:[NSDate date]];
[datePicker presentInView:self.view withBlock:^(BOOL madeChoice) {
  if (madeChoice) {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterLongStyle];
    NSLog(@"You chose the date %@", 
      [dateFormatter stringFromDate:datePicker.selectedDate]);
  }
}];

Demo

Take a look at this video:

BSModalPickerView Demo

Requirements

BSModalPickerView requires iOS 5.x or greater.

License

Usage is provided under the MIT License. See LICENSE for the full details.

About

A custom view component that presents a UIPickerView with a simple list of options, along with a toolbar for Done/Cancel and a faded backdrop view.

Resources

License

Stars

Watchers

Forks

Packages

No packages published