Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions MMPickerView/MMPickerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@ extern NSString * const MMtoolbarBackgroundImage;
extern NSString * const MMtextAlignment;
extern NSString * const MMshowsSelectionIndicator;

@protocol MMPickerViewDelegate <NSObject>

- (void)didDismissPickerView;

@end

@interface MMPickerView: UIView

+(void)showPickerViewInView: (UIView *)view
withStrings: (NSArray *)strings
withOptions: (NSDictionary *)options
completion: (void(^)(NSString *selectedString))completion;

+(void)showPickerViewInView:(UIView *)view
withDelegate:(id<MMPickerViewDelegate>)delegate
withStrings:(NSArray *)strings
withOptions:(NSDictionary *)options
completion:(void (^)(NSString *))completion;

+(void)showPickerViewInView: (UIView *)view
withObjects: (NSArray *)objects
withOptions: (NSDictionary *)options
Expand Down
36 changes: 32 additions & 4 deletions MMPickerView/MMPickerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

@interface MMPickerView () <UIPickerViewDelegate, UIPickerViewDataSource>

@property (strong, nonatomic) id<MMPickerViewDelegate> pickerViewDelegate;
@property (nonatomic, strong) UILabel *pickerViewLabel;
@property (nonatomic, strong) UIView *pickerViewLabelView;
@property (nonatomic, strong) UIView *pickerContainerView;
Expand Down Expand Up @@ -71,6 +72,23 @@ +(void)showPickerViewInView:(UIView *)view

}

+(void)showPickerViewInView:(UIView *)view
withDelegate:(id<MMPickerViewDelegate>)delegate
withStrings:(NSArray *)strings
withOptions:(NSDictionary *)options
completion:(void (^)(NSString *))completion{

[[self sharedView] initializePickerViewInView:view
withArray:strings
withOptions:options];

[[self sharedView] setPickerViewDelegate:delegate];
[[self sharedView] setPickerHidden:NO callBack:nil];
[self sharedView].onDismissCompletion = completion;
[view addSubview:[self sharedView]];

}

+(void)showPickerViewInView:(UIView *)view
withObjects:(NSArray *)objects
withOptions:(NSDictionary *)options
Expand All @@ -89,8 +107,18 @@ +(void)showPickerViewInView:(UIView *)view

#pragma mark - Dismiss Methods

+(void)dismissWithCompletion:(void (^)(NSString *))completion{
[[self sharedView] setPickerHidden:YES callBack:completion];
+(void)dismissWithCompletion:(void (^)(NSString *))completion
{
[[self sharedView] setPickerHidden:YES callBack:completion];
[self performSelector:@selector(callPickerViewDismissDelegate:) withObject:nil afterDelay:0.3];
}

+ (IBAction)callPickerViewDismissDelegate:(id)sender
{
if ([self sharedView].pickerViewDelegate)
{
[[self sharedView].pickerViewDelegate didDismissPickerView];
}
}

-(void)dismiss{
Expand Down Expand Up @@ -180,7 +208,7 @@ -(void)initializePickerViewInView: (UIView *)view
[self addSubview:_pickerViewContainerView];

//PickerView Container with top bar
_pickerContainerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, _pickerViewContainerView.bounds.size.height - 260.0, 320.0, 260.0)];
_pickerContainerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, _pickerViewContainerView.bounds.size.height - 260.0, _pickerViewContainerView.bounds.size.width, 260.0)];

//Default Color Values (if colors == nil)

Expand Down Expand Up @@ -273,7 +301,7 @@ -(void)initializePickerViewInView: (UIView *)view
*/

//Add pickerView
_pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 320.0, 216.0)];
_pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, _pickerViewContainerView.bounds.size.width, 216.0)];
[_pickerView setDelegate:self];
[_pickerView setDataSource:self];
[_pickerView setShowsSelectionIndicator: _pickerViewShowsSelectionIndicator];//YES];
Expand Down