diff --git a/MMPickerView/MMPickerView.h b/MMPickerView/MMPickerView.h index abbf7c1..71f7439 100644 --- a/MMPickerView/MMPickerView.h +++ b/MMPickerView/MMPickerView.h @@ -19,6 +19,12 @@ extern NSString * const MMtoolbarBackgroundImage; extern NSString * const MMtextAlignment; extern NSString * const MMshowsSelectionIndicator; +@protocol MMPickerViewDelegate + +- (void)didDismissPickerView; + +@end + @interface MMPickerView: UIView +(void)showPickerViewInView: (UIView *)view @@ -26,6 +32,12 @@ extern NSString * const MMshowsSelectionIndicator; withOptions: (NSDictionary *)options completion: (void(^)(NSString *selectedString))completion; ++(void)showPickerViewInView:(UIView *)view + withDelegate:(id)delegate + withStrings:(NSArray *)strings + withOptions:(NSDictionary *)options + completion:(void (^)(NSString *))completion; + +(void)showPickerViewInView: (UIView *)view withObjects: (NSArray *)objects withOptions: (NSDictionary *)options diff --git a/MMPickerView/MMPickerView.m b/MMPickerView/MMPickerView.m index 0986641..6fc5b8a 100644 --- a/MMPickerView/MMPickerView.m +++ b/MMPickerView/MMPickerView.m @@ -21,6 +21,7 @@ @interface MMPickerView () +@property (strong, nonatomic) id pickerViewDelegate; @property (nonatomic, strong) UILabel *pickerViewLabel; @property (nonatomic, strong) UIView *pickerViewLabelView; @property (nonatomic, strong) UIView *pickerContainerView; @@ -71,6 +72,23 @@ +(void)showPickerViewInView:(UIView *)view } ++(void)showPickerViewInView:(UIView *)view + withDelegate:(id)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 @@ -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{ @@ -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) @@ -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];