forked from TimCinel/ActionSheetPicker
-
-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from skywinder/alexperezpaya-master
Merging :)
- Loading branch information
Showing
129 changed files
with
153 additions
and
5,973 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
###Basic Usage | ||
|
||
```obj-c | ||
// 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 customisation: | ||
```obj-c | ||
- (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: | ||
```obj-c | ||
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: | ||
```obj-c | ||
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: | ||
|
||
```obj-c | ||
// 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)]; | ||
``` | ||
#### Action by clicking outside of the picker: | ||
Use property `tapDismissAction` to specify action, by clicking outside area of the picker: | ||
- `TapActionNone` (default) | ||
- `TapActionSuccess` | ||
- `TapActionCancel` | ||
#### Other customisations: | ||
look at `AbstractActionSheetPicker` properties: | ||
- `toolbar` | ||
- `title` | ||
- `pickerView` | ||
- `viewSize` | ||
- `customButtons` | ||
- `hideCancel` - show or hide cancel button. | ||
- `titleTextAttributes` - default is nil. Used to specify Title Label attributes. | ||
- `attributedTitle` - default is nil. If titleTextAttributes not nil this value ignored. | ||
- `popoverBackgroundViewClass` -allow popover customization on iPad | ||
- `supportedInterfaceOrientations` - You can set your own supportedInterfaceOrientations value to prevent dismissing picker in some special cases. | ||
- `tapDismissAction` - to specify action, by clicking outside area of the picker | ||
- `TapActionNone` | ||
- `TapActionSuccess` | ||
- `TapActionCancel` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.