diff --git a/Demo/Classes/MMTestViewController.h b/Demo/Classes/MMTestViewController.h
index 85f8df9..c58f8b1 100644
--- a/Demo/Classes/MMTestViewController.h
+++ b/Demo/Classes/MMTestViewController.h
@@ -10,7 +10,7 @@
#import "MMPickerView.h"
@interface MMTestViewController : UIViewController
-- (IBAction)showPickerViewButtonPressed:(id)sender;
+
@property (weak, nonatomic) IBOutlet UILabel *label;
@end
diff --git a/Demo/Classes/MMTestViewController.m b/Demo/Classes/MMTestViewController.m
index 7432c73..cd3c33b 100644
--- a/Demo/Classes/MMTestViewController.m
+++ b/Demo/Classes/MMTestViewController.m
@@ -33,142 +33,169 @@ - (void)viewDidLoad
}
+- (IBAction)showSimplePickerView:(id)sender {
+ /*
+ Options:
+
+ MMbackgroundColor - UIColor
+ MMtextColor - UIColor
+ MMtoolbarColor - UIColor
+ MMbuttonColor - UIColor
+ MMfont - UIFont
+ MMvalueY - NSInteger
+ MMselectedObject - An Object ex: a string
+ MMtoolbarBackgroundImage - UIImage
+ MMtextAlignment - NSNumber (@0 - Left, @1 - Center, @2 - Right)
+
+ ***************
+ DON'T FORGET TO ONLY UNCOMMENT ONE EXAMPLE AT A TIME, OTHERWISE YOU WILL HAVE SEVERAL PICKERVIEWS AT THE SAME TIME.
+ JUST SAYIN' :-)
+ ***************
+ */
+
+
+ /*
+ //Simple PickerView with array of strings
+ NSArray *strings = @[@"This", @"is", @"just", @"an array", @"of strings."];
+
+ [MMPickerView showPickerViewInView:self.view
+ withStrings:strings
+ withOptions:nil
+ completion:^(NSString *selectedString) {
+ //selectedString is the return value which you can use as you wish
+ self.label.text = selectedString;
+ }];
+ */
+
+
+ /*
+
+ //PickerView with Custom look, with array of strings
+ UIFont *customFont = [UIFont fontWithName:@"Palatino-Bold" size:19.0];
+ NSDictionary *options = @{MMbackgroundColor:[UIColor clearColor],
+ MMtextColor: [UIColor colorWithRed:0.063 green:0.180 blue:0.216 alpha:1],
+ MMtoolbarColor:[UIColor colorWithRed:0.169 green:0.733 blue:0.847 alpha:1],
+ MMbuttonColor:[UIColor colorWithRed:0.969 green:0.553 blue:0.247 alpha:1],
+ MMfont: customFont,
+ MMvalueY: @5};
+
+ [MMPickerView showPickerViewInView:self.view
+ withStrings:_stringsArray
+ withOptions:options
+ completion:^(NSString *selectedString) {
+ //selectedString is the return value which you can use as you wish
+ self.label.text = selectedString;
+ }];
+ */
+
+
+ /*
+ //PickerView with selectedValue functionality, and customized look, with array of strings
+ [MMPickerView showPickerViewInView:self.view
+ withStrings:_stringsArray
+ withOptions:@{MMbackgroundColor: [UIColor whiteColor],
+ MMtextColor: [UIColor blackColor],
+ MMtoolbarColor: [UIColor whiteColor],
+ MMbuttonColor: [UIColor blueColor],
+ MMfont: [UIFont systemFontOfSize:18],
+ MMvalueY: @3,
+ MMselectedObject:_selectedString,
+ MMtextAlignment:@1}
+ completion:^(NSString *selectedString) {
+
+ _label.text = selectedString;
+ _selectedString = selectedString;
+ }];
+ */
+
+
+ /*
+ //This one looks nice on iOS 7, but not iOS 6.
+ //PickerView with selectedValue functionality, and customized look, with array of strings
+
+ [MMPickerView showPickerViewInView:self.view
+ withStrings:_stringsArray
+ withOptions:@{MMbackgroundColor: [UIColor blackColor],
+ MMtextColor: [UIColor whiteColor],
+ MMtoolbarColor: [UIColor blackColor],
+ MMbuttonColor: [UIColor whiteColor],
+ MMfont: [UIFont systemFontOfSize:18],
+ MMvalueY: @3,
+ MMselectedObject:_selectedString}
+ completion:^(NSString *selectedString) {
+
+ _label.text = selectedString;
+ _selectedString = selectedString;
+ }];
+ */
+
+
+
+ //PickerView using array of objects
+ NSArray *objects = @[@"This is a mix of objects", @14, @13.3, @"A string", @1];
+
+ [MMPickerView showPickerViewInView:self.view
+ withObjects:objects
+ withOptions:nil
+ objectToStringConverter:^NSString *(id object) {
+ return [object description];
+ }
+ completion:^(id selectedObject) {
+
+ _label.text = [selectedObject description];
+ }];
+
+
+
+ /*
+ //PickerView using array of objects, with selectedObject functionality
+ [MMPickerView showPickerViewInView:self.view
+ withObjects:_objectsArray
+ withOptions:@{MMselectedObject:_selectedObject}
+ objectToStringConverter:^NSString *(id object) {
+ return [object description];
+ }
+ completion:^(id selectedObject) {
+ _label.text = [selectedObject description];
+ _selectedObject = selectedObject;
+ }];
+ */
+}
-- (IBAction)showPickerViewButtonPressed:(id)sender {
-
- /*
- Options:
-
- MMbackgroundColor - UIColor
- MMtextColor - UIColor
- MMtoolbarColor - UIColor
- MMbuttonColor - UIColor
- MMfont - UIFont
- MMvalueY - NSInteger
- MMselectedObject - An Object ex: a string
- MMtoolbarBackgroundImage - UIImage
- MMtextAlignment - NSNumber (@0 - Left, @1 - Center, @2 - Right)
-
- ***************
- DON'T FORGET TO ONLY UNCOMMENT ONE EXAMPLE AT A TIME, OTHERWISE YOU WILL HAVE SEVERAL PICKERVIEWS AT THE SAME TIME.
- JUST SAYIN' :-)
- ***************
- */
-
-
- /*
- //Simple PickerView with array of strings
- NSArray *strings = @[@"This", @"is", @"just", @"an array", @"of strings."];
-
- [MMPickerView showPickerViewInView:self.view
- withStrings:strings
- withOptions:nil
- completion:^(NSString *selectedString) {
- //selectedString is the return value which you can use as you wish
- self.label.text = selectedString;
- }];
- */
-
-
- /*
-
- //PickerView with Custom look, with array of strings
- UIFont *customFont = [UIFont fontWithName:@"Palatino-Bold" size:19.0];
- NSDictionary *options = @{MMbackgroundColor:[UIColor clearColor],
- MMtextColor: [UIColor colorWithRed:0.063 green:0.180 blue:0.216 alpha:1],
- MMtoolbarColor:[UIColor colorWithRed:0.169 green:0.733 blue:0.847 alpha:1],
- MMbuttonColor:[UIColor colorWithRed:0.969 green:0.553 blue:0.247 alpha:1],
- MMfont: customFont,
- MMvalueY: @5};
-
- [MMPickerView showPickerViewInView:self.view
- withStrings:_stringsArray
- withOptions:options
- completion:^(NSString *selectedString) {
- //selectedString is the return value which you can use as you wish
- self.label.text = selectedString;
- }];
- */
-
-
-
- //PickerView with selectedValue functionality, and customized look, with array of strings
- [MMPickerView showPickerViewInView:self.view
- withStrings:_stringsArray
- withOptions:@{MMbackgroundColor: [UIColor whiteColor],
- MMtextColor: [UIColor blackColor],
- MMtoolbarColor: [UIColor whiteColor],
- MMbuttonColor: [UIColor blueColor],
- MMfont: [UIFont systemFontOfSize:18],
- MMvalueY: @3,
- MMselectedObject:_selectedString,
- MMtextAlignment:@1}
- completion:^(NSString *selectedString) {
-
- _label.text = selectedString;
- _selectedString = selectedString;
- }];
-
-
-
- /*
- //This one looks nice on iOS 7, but not iOS 6.
- //PickerView with selectedValue functionality, and customized look, with array of strings
-
- [MMPickerView showPickerViewInView:self.view
- withStrings:_stringsArray
- withOptions:@{MMbackgroundColor: [UIColor blackColor],
- MMtextColor: [UIColor whiteColor],
- MMtoolbarColor: [UIColor blackColor],
- MMbuttonColor: [UIColor whiteColor],
- MMfont: [UIFont systemFontOfSize:18],
- MMvalueY: @3,
- MMselectedObject:_selectedString}
- completion:^(NSString *selectedString) {
-
- _label.text = selectedString;
- _selectedString = selectedString;
- }];
- */
-
-
-
- /*
- //PickerView using array of objects
- NSArray *objects = @[@"This is a mix of objects", @14, @13.3, @"A string", @1];
-
- [MMPickerView showPickerViewInView:self.view
- withObjects:objects
- withOptions:nil
- objectToStringConverter:^NSString *(id object) {
- return [object description];
- }
- completion:^(id selectedObject) {
-
- _label.text = [selectedObject description];
- }];
- */
-
-
-
- /*
- //PickerView using array of objects, with selectedObject functionality
- [MMPickerView showPickerViewInView:self.view
- withObjects:_objectsArray
- withOptions:@{MMselectedObject:_selectedObject}
- objectToStringConverter:^NSString *(id object) {
- return [object description];
- }
- completion:^(id selectedObject) {
- _label.text = [selectedObject description];
- _selectedObject = selectedObject;
- }];
- */
-
-
+- (IBAction)showMultiComponentPickerView:(id)sender {
+ NSArray *components = @[@[@"1", @"2", @"3"], @[@"1", @"2", @"3"], @[@"1", @"2", @"3"], @[@"1", @"2", @"3"]];
+ NSArray *selected = @[@"1", @"2", @"3", @"1"];
+
+ //PickerView using array of objects, with selectedObject functionality
+ [MMPickerView showPickerViewInView:self.view
+ withArrays:components
+ withComponentSizes:nil
+ withOptions:@{MMselectedObject: selected}
+ completion:^(NSArray *selectedComponents) {
+ NSString *str = [selectedComponents componentsJoinedByString:@""];
+ self.label.text = str;
+ }
+ ];
}
+- (IBAction)showMultiComponentWithSizesPickerView:(id)sender {
+ NSArray *components = @[@[@""], @[@"1", @"2", @"3"], @[@"1", @"2", @"3"], @[@"1", @"2", @"3"], @[@"1", @"2", @"3"], @[@""]];
+ NSArray *selected = @[@"", @"1", @"2", @"3", @"1", @"",];
+
+ NSArray *sizes = @[@(100),@(30),@(30),@(30),@(30),@(100)];
+
+ //PickerView using array of objects, with selectedObject functionality
+ [MMPickerView showPickerViewInView:self.view
+ withArrays:components
+ withComponentSizes:sizes
+ withOptions:@{MMselectedObject: selected}
+ completion:^(NSArray *selectedComponents) {
+ NSString *str = [selectedComponents componentsJoinedByString:@""];
+ self.label.text = str;
+ }
+ ];
+}
diff --git a/Demo/MMTestViewController.xib b/Demo/MMTestViewController.xib
index db1437b..69f178d 100644
--- a/Demo/MMTestViewController.xib
+++ b/Demo/MMTestViewController.xib
@@ -1,284 +1,86 @@
-
-
-
- 1552
- 12E55
- 3084
- 1187.39
- 626.00
-
-
- IBProxyObject
- IBUIButton
- IBUILabel
- IBUIView
-
-
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
-
-
-
-
-
-
-
-
- NO
-
-
-
- label
-
-
-
- 13
-
-
-
- view
-
-
-
- 10
-
-
-
- showPickerViewButtonPressed:
-
-
- 7
-
- 11
-
-
-
-
-
- 0
-
-
-
-
-
- -1
-
-
- File's Owner
-
-
- -2
-
-
-
-
- 1
-
-
-
-
-
-
-
-
- 4
-
-
-
-
- 12
-
-
-
-
-
-
- MMTestViewController
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
-
- UIResponder
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
-
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
-
-
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
-
-
- com.apple.InterfaceBuilder.IBCocoaTouchPlugin
-
-
-
-
-
-
-
-
-
-
-
- MMTestViewController
- UIViewController
-
- showPickerViewButtonPressed:
- id
-
-
- showPickerViewButtonPressed:
-
- showPickerViewButtonPressed:
- id
-
-
-
- label
- UILabel
-
-
- label
-
- label
- UILabel
-
-
-
- IBProjectSource
- ./Classes/MMTestViewController.h
-
-
-
-
- 0
- IBCocoaTouchFramework
-
- com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS
-
-
-
- com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS
-
-
-
- com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3
-
-
- YES
- 3
- 2083
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Demo/example_multiple_components.png b/Demo/example_multiple_components.png
new file mode 100644
index 0000000..4ce6a2a
Binary files /dev/null and b/Demo/example_multiple_components.png differ
diff --git a/MMPickerView/MMPickerView.h b/MMPickerView/MMPickerView.h
index abbf7c1..c668ed7 100644
--- a/MMPickerView/MMPickerView.h
+++ b/MMPickerView/MMPickerView.h
@@ -32,6 +32,13 @@ extern NSString * const MMshowsSelectionIndicator;
objectToStringConverter: (NSString *(^)(id object))converter
completion: (void(^)(id selectedObject))completion;
+// Provides a picker with multiple comonents
++(void)showPickerViewInView: (UIView *)view
+ withArrays: (NSArray *)arrays
+ withComponentSizes: (NSArray *)sizes
+ withOptions: (NSDictionary *)options
+ completion: (void (^)(NSArray* selectedComponents))completion;
+
+(void)dismissWithCompletion: (void(^)(NSString *))completion;
@end
diff --git a/MMPickerView/MMPickerView.m b/MMPickerView/MMPickerView.m
index 0986641..e21466a 100644
--- a/MMPickerView/MMPickerView.m
+++ b/MMPickerView/MMPickerView.m
@@ -32,12 +32,14 @@ @interface MMPickerView ()
@property (nonatomic, strong) UIButton *pickerDoneButton;
@property (nonatomic, strong) UIPickerView *pickerView;
@property (nonatomic, strong) NSArray *pickerViewArray;
+@property (nonatomic, strong) NSArray *pickerViewComponentSizes;
@property (nonatomic, strong) UIColor *pickerViewTextColor;
@property (nonatomic, strong) UIFont *pickerViewFont;
@property (nonatomic, assign) CGFloat yValueFromTop;
@property (nonatomic, assign) NSInteger pickerViewTextAlignment;
@property (nonatomic, assign) BOOL pickerViewShowsSelectionIndicator;
-@property (copy) void (^onDismissCompletion)(NSString *);
+@property (nonatomic, assign) BOOL multidimensional;
+@property (copy) void (^onDismissCompletion)(id);
@property (copy) NSString *(^objectToStringConverter)(id object);
@end
@@ -63,6 +65,8 @@ +(void)showPickerViewInView:(UIView *)view
[[self sharedView] initializePickerViewInView:view
withArray:strings
+ withComponentSizes:nil
+ isMultidimensional:NO
withOptions:options];
[[self sharedView] setPickerHidden:NO callBack:nil];
@@ -81,24 +85,45 @@ +(void)showPickerViewInView:(UIView *)view
[self sharedView].onDismissCompletion = completion;
[[self sharedView] initializePickerViewInView:view
withArray:objects
+ withComponentSizes:nil
+ isMultidimensional:NO
withOptions:options];
[[self sharedView] setPickerHidden:NO callBack:nil];
[view addSubview:[self sharedView]];
}
++(void)showPickerViewInView: (UIView *)view
+ withArrays: (NSArray *)arrays
+ withComponentSizes: (NSArray *)sizes
+ withOptions: (NSDictionary *)options
+ completion: (void (^)(NSArray* selectedComponents))completion{
+
+ [[self sharedView] initializePickerViewInView:view
+ withArray:arrays
+ withComponentSizes:sizes
+ isMultidimensional:YES
+ withOptions:options];
+
+ [[self sharedView] setPickerHidden:NO callBack:nil];
+ [self sharedView].onDismissCompletion = completion;
+ [view addSubview:[self sharedView]];
+
+}
+
+
#pragma mark - Dismiss Methods
+(void)dismissWithCompletion:(void (^)(NSString *))completion{
- [[self sharedView] setPickerHidden:YES callBack:completion];
+ [[self sharedView] setPickerHidden:YES callBack:completion];
}
-(void)dismiss{
- [MMPickerView dismissWithCompletion:self.onDismissCompletion];
+ [MMPickerView dismissWithCompletion:self.onDismissCompletion];
}
+(void)removePickerView{
- [[self sharedView] removeFromSuperview];
+ [[self sharedView] removeFromSuperview];
}
#pragma mark - Show/hide PickerView methods
@@ -131,17 +156,41 @@ -(void)setPickerHidden: (BOOL)hidden
-(void)initializePickerViewInView: (UIView *)view
withArray: (NSArray *)array
+ withComponentSizes: (NSArray *)sizes
+ isMultidimensional: (BOOL) multidemsional
withOptions: (NSDictionary *)options {
_pickerViewArray = array;
+ _multidimensional = multidemsional;
+ _pickerViewComponentSizes = sizes;
+
+ // get number of components
+ NSInteger numberComponents = multidemsional ? array.count : 1;
+
+ // if no component sizes were given just calculate them
+ if(_pickerViewComponentSizes == nil || numberComponents != _pickerViewComponentSizes.count)
+ {
+ _pickerViewComponentSizes = [[NSMutableArray alloc] initWithCapacity:numberComponents];
+ for(int i=0; i
## Installation
@@ -48,6 +52,12 @@ You can show the PickerView:
withOptions: (NSDictionary *)options
objectToStringConverter: (NSString *(^)(id object))converter
completion: (void(^)(id selectedObject))completion;
+
++(void)showPickerViewInView: (UIView *)view
+ withArrays: (NSArray *)arrays
+ withComponentSizes: (NSArray *)sizes
+ withOptions: (NSDictionary *)options
+ completion: (void (^)(NSArray* selectedComponents))completion;
```
@@ -85,6 +95,24 @@ You can show the PickerView:
}];
```
+#### Example 3 - Show with multiple components.
+```objective-c
+
+ NSArray *components = @[@[@""], @[@"1", @"2", @"3"], @[@"1", @"2", @"3"], @[@"1", @"2", @"3"], @[@"1", @"2", @"3"], @[@""]];
+ NSArray *selected = @[@"", @"1", @"2", @"3", @"1", @"",];
+ NSArray *sizes = @[@(100), @(30), @(30), @(30), @(30), @(100)];
+
+ //PickerView using array of objects, with selectedObject functionality
+ [MMPickerView showPickerViewInView:self.view
+ withArrays:components
+ withComponentSizes:sizes
+ withOptions:@{MMselectedObject: selected}
+ completion:^(NSArray *selectedComponents) {
+ // interpret the selected components
+ }
+ ];
+```
+
### Customizing MMPickerView
Both show methods use a `NSDictionary` to set the options of the `MMPickerView`. If you want a native looking PickerView, just `withOptions: nil`. In case of customization, use any of the different properties to customize the PickerView. All of the properties are optional, which means that if you only want to change one thing, like for eg the text color you can do like this, `withOptions: @{MMtextColor: [UIColor redColor]}`
@@ -116,7 +144,7 @@ Both show methods use a `NSDictionary` to set the options of the `MMPickerView`.
*/
```
-#### Example 3 - Show with an array of strings and with custom colors and custom font.
+#### Example 4 - Show with an array of strings and with custom colors and custom font.
```objective-c
NSArray *strings = @[@"This", @"is", @"just", @"an array", @"of strings."];
@@ -143,7 +171,7 @@ A useful feature is to let the PickerView select whatever was selected last time
-#### Example 4 - Show with an array of strings set selectedValue on PickerView.
+#### Example 5 - Show with an array of strings set selectedValue on PickerView.
```objective-c