From ce977a999c85c306b522cf58cc17f9c1b939a185 Mon Sep 17 00:00:00 2001 From: AmitaiB Date: Thu, 31 Mar 2016 23:47:14 -0400 Subject: [PATCH 1/5] Adds show/hide AnimationTypes -SimplyAppear- and -SimplyDisappear- i.e., None --- SCLAlertView/SCLAlertView.h | 6 ++++-- SCLAlertView/SCLAlertView.m | 32 ++++++++++++++++++++++++++++ SCLAlertViewExample/ViewController.m | 6 +++--- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/SCLAlertView/SCLAlertView.h b/SCLAlertView/SCLAlertView.h index 0c2f386..d5ef469 100755 --- a/SCLAlertView/SCLAlertView.h +++ b/SCLAlertView/SCLAlertView.h @@ -50,7 +50,8 @@ typedef NS_ENUM(NSInteger, SCLAlertViewHideAnimation) SlideOutToLeft, SlideOutToRight, SlideOutToCenter, - SlideOutFromCenter + SlideOutFromCenter, + SimplyDisappear }; /** Alert show animation styles @@ -65,7 +66,8 @@ typedef NS_ENUM(NSInteger, SCLAlertViewShowAnimation) SlideInFromLeft, SlideInFromRight, SlideInFromCenter, - SlideInToCenter + SlideInToCenter, + SimplyAppear }; /** Alert background styles diff --git a/SCLAlertView/SCLAlertView.m b/SCLAlertView/SCLAlertView.m index 1839dc3..a0bf244 100755 --- a/SCLAlertView/SCLAlertView.m +++ b/SCLAlertView/SCLAlertView.m @@ -1245,6 +1245,10 @@ - (void)showView case SlideInToCenter: [self slideInToCenter]; break; + + case SimplyAppear: + [self simplyAppear]; + break; } } @@ -1281,6 +1285,10 @@ - (void)hideView case SlideOutFromCenter: [self slideOutFromCenter]; break; + + case SimplyDisappear: + [self simplyDisappear]; + break; } if (_activityIndicatorView) @@ -1399,6 +1407,18 @@ - (void)slideOutFromCenter }]; } +- (void)simplyDisappear +{ + self.backgroundView.alpha = _backgroundOpacity; + self.view.alpha = 1.0f; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + self.backgroundView.alpha = 0.0f; + self.view.alpha = 0.0f; + }); +} + + #pragma mark - Show Animations - (void)fadeIn @@ -1572,6 +1592,18 @@ - (void)slideInToCenter }]; } +- (void)simplyAppear +{ + self.backgroundView.alpha = 0.0f; + self.view.alpha = 0.0f; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + self.backgroundView.alpha = _backgroundOpacity; + self.view.alpha = 1.0f; + }); +} + + @end @interface SCLALertViewTextFieldBuilder() diff --git a/SCLAlertViewExample/ViewController.m b/SCLAlertViewExample/ViewController.m index c3e8e2a..6caeb0e 100644 --- a/SCLAlertViewExample/ViewController.m +++ b/SCLAlertViewExample/ViewController.m @@ -84,7 +84,7 @@ - (IBAction)showNotice:(id)sender SCLAlertView *alert = [[SCLAlertView alloc] init]; alert.backgroundType = Blur; - + alert.showAnimationType = FadeIn; [alert showNotice:self title:kNoticeTitle subTitle:@"You've just displayed this awesome Pop Up View with blur effect" closeButtonTitle:kButtonTitle duration:0.0f]; } @@ -100,7 +100,7 @@ - (IBAction)showInfo:(id)sender SCLAlertView *alert = [[SCLAlertView alloc] init]; alert.shouldDismissOnTapOutside = YES; - + alert.showAnimationType = SimplyAppear; [alert alertIsDismissed:^{ NSLog(@"SCLAlertView dismissed!"); }]; @@ -113,7 +113,7 @@ - (IBAction)showEdit:(id)sender SCLAlertView *alert = [[SCLAlertView alloc] init]; SCLTextView *textField = [alert addTextField:@"Enter your name"]; - + alert.hideAnimationType = SimplyDisappear; [alert addButton:@"Show Name" actionBlock:^(void) { NSLog(@"Text value: %@", textField.text); }]; From 5d8ae7b2f82b26dbffa12752d7dd268ff697faa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Antonio=20Espi=CC=81n=20Mora?= Date: Fri, 29 Apr 2016 12:31:54 +0200 Subject: [PATCH 2/5] Feature to show buttons horizontally. --- SCLAlertView/SCLAlertView.h | 6 ++++++ SCLAlertView/SCLAlertView.m | 29 ++++++++++++++++++++++++----- SCLAlertView/SCLButton.h | 8 ++++++++ SCLAlertView/SCLButton.m | 8 ++++++++ 4 files changed, 46 insertions(+), 5 deletions(-) mode change 100644 => 100755 SCLAlertView/SCLButton.h mode change 100644 => 100755 SCLAlertView/SCLButton.m diff --git a/SCLAlertView/SCLAlertView.h b/SCLAlertView/SCLAlertView.h index d5ef469..36d2f63 100755 --- a/SCLAlertView/SCLAlertView.h +++ b/SCLAlertView/SCLAlertView.h @@ -222,6 +222,12 @@ typedef NS_ENUM(NSInteger, SCLAlertViewBackground) */ @property (nonatomic) UIStatusBarStyle statusBarStyle; +/** Set horizontal alignment for buttons + * + * Horizontal aligment instead of vertically if YES + */ +@property (nonatomic) BOOL horizontalButtons; + /** Initialize SCLAlertView using a new window. * * Init with new window diff --git a/SCLAlertView/SCLAlertView.m b/SCLAlertView/SCLAlertView.m index a0bf244..db88e0f 100755 --- a/SCLAlertView/SCLAlertView.m +++ b/SCLAlertView/SCLAlertView.m @@ -380,10 +380,17 @@ - (void)viewWillLayoutSubviews } // Buttons + CGFloat x = 12.0f; for (SCLButton *btn in _buttons) { - btn.frame = CGRectMake(12.0f, y, btn.frame.size.width, btn.frame.size.height); - y += btn.frame.size.height + 10.0f; + btn.frame = CGRectMake(x, y, btn.frame.size.width, btn.frame.size.height); + + // Add horizontal or vertical offset acording on _horizontalButtons parameter + if (_horizontalButtons) { + x += btn.frame.size.width + 10.0f; + } else { + y += btn.frame.size.height + 10.0f; + } } // Adapt window height according to icon size @@ -684,12 +691,24 @@ - (SCLButton *)addButton:(NSString *)title [btn setTitle:title forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont fontWithName:_buttonsFontFamily size:_buttonsFontSize]; - // Update view height - self.windowHeight += (btn.frame.size.height + ADD_BUTTON_PADDING); - [_contentView addSubview:btn]; [_buttons addObject:btn]; + if (_horizontalButtons) { + // Update buttons width according to the number of buttons + for (SCLButton *bttn in _buttons) { + [bttn adjustWidthWithWindowWidth:self.windowWidth numberOfButtons:[_buttons count]]; + } + + // Update view height + if (!([_buttons count] > 1)) { + self.windowHeight += (btn.frame.size.height + ADD_BUTTON_PADDING); + } + } else { + // Update view height + self.windowHeight += (btn.frame.size.height + ADD_BUTTON_PADDING); + } + return btn; } diff --git a/SCLAlertView/SCLButton.h b/SCLAlertView/SCLButton.h old mode 100644 new mode 100755 index 8a46e46..b19ed77 --- a/SCLAlertView/SCLButton.h +++ b/SCLAlertView/SCLButton.h @@ -98,4 +98,12 @@ typedef NS_ENUM(NSInteger, SCLActionType) */ - (instancetype)initWithWindowWidth:(CGFloat)windowWidth; +/** Adjust width of the button according to the width of the alert and + * the number of buttons. Only used when buttons are horizontally aligned. + * + * @param windowWith The width of the alert. + * @param numberOfButtons The number of buttons in the alert. + */ +- (void)adjustWidthWithWindowWidth:(CGFloat)windowWidht numberOfButtons:(NSUInteger)numberOfButtons; + @end diff --git a/SCLAlertView/SCLButton.m b/SCLAlertView/SCLButton.m old mode 100644 new mode 100755 index cd84c15..2288ea6 --- a/SCLAlertView/SCLButton.m +++ b/SCLAlertView/SCLButton.m @@ -63,6 +63,14 @@ - (void)setupWithWindowWidth:(CGFloat)windowWidth self.layer.cornerRadius = 3.0f; } +- (void)adjustWidthWithWindowWidth:(CGFloat)windowWidht numberOfButtons:(NSUInteger)numberOfButtons +{ + CGFloat allButtonsWidth = windowWidht - (MARGIN_BUTTON * 2); + CGFloat buttonWidth = (allButtonsWidth - ((numberOfButtons - 1) * 10)) / numberOfButtons; + + self.frame = CGRectMake(0.0f, 0.0f, buttonWidth, MIN_HEIGHT); +} + - (void)setTitle:(NSString *)title forState:(UIControlState)state { [super setTitle:title forState:state]; From 5c6e3c6be1df5709390732ef34f6fb963c737f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Antonio=20Espi=CC=81n=20Mora?= Date: Fri, 29 Apr 2016 13:50:25 +0200 Subject: [PATCH 3/5] Added an example using horizontal buttons. --- .../Base.lproj/Storyboard.storyboard | 61 +++++++++++-------- SCLAlertViewExample/ViewController.h | 1 + SCLAlertViewExample/ViewController.m | 27 ++++++++ 3 files changed, 64 insertions(+), 25 deletions(-) diff --git a/SCLAlertViewExample/Base.lproj/Storyboard.storyboard b/SCLAlertViewExample/Base.lproj/Storyboard.storyboard index 7c01a6e..f788db6 100644 --- a/SCLAlertViewExample/Base.lproj/Storyboard.storyboard +++ b/SCLAlertViewExample/Base.lproj/Storyboard.storyboard @@ -1,8 +1,8 @@ - + - + @@ -32,8 +32,17 @@ + + - + + + - + + + @@ -169,23 +189,14 @@ - - - diff --git a/SCLAlertViewExample/ViewController.h b/SCLAlertViewExample/ViewController.h index 81de180..4ba5548 100644 --- a/SCLAlertViewExample/ViewController.h +++ b/SCLAlertViewExample/ViewController.h @@ -11,6 +11,7 @@ @interface ViewController : UIViewController - (IBAction)showSuccess:(id)sender; +- (IBAction)showSuccessWithHorizontalButtons:(id)sender; - (IBAction)showError:(id)sender; - (IBAction)showNotice:(id)sender; - (IBAction)showWarning:(id)sender; diff --git a/SCLAlertViewExample/ViewController.m b/SCLAlertViewExample/ViewController.m index 6caeb0e..4a7bef9 100644 --- a/SCLAlertViewExample/ViewController.m +++ b/SCLAlertViewExample/ViewController.m @@ -70,6 +70,33 @@ - (IBAction)showSuccess:(id)sender [alert showSuccess:kSuccessTitle subTitle:kSubtitle closeButtonTitle:kButtonTitle duration:0.0f]; } +- (IBAction)showSuccessWithHorizontalButtons:(id)sender { + SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindow]; + [alert setHorizontalButtons:YES]; + + SCLButton *button = [alert addButton:@"First Button" target:self selector:@selector(firstButton)]; + + button.buttonFormatBlock = ^NSDictionary* (void) + { + NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init]; + + buttonConfig[@"backgroundColor"] = [UIColor whiteColor]; + buttonConfig[@"textColor"] = [UIColor blackColor]; + buttonConfig[@"borderWidth"] = @2.0f; + buttonConfig[@"borderColor"] = [UIColor greenColor]; + + return buttonConfig; + }; + + [alert addButton:@"Second Button" actionBlock:^(void) { + NSLog(@"Second button tapped"); + }]; + + alert.soundURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/right_answer.mp3", [NSBundle mainBundle].resourcePath]]; + + [alert showSuccess:kSuccessTitle subTitle:kSubtitle closeButtonTitle:kButtonTitle duration:0.0f]; +} + - (IBAction)showError:(id)sender { SCLAlertView *alert = [[SCLAlertView alloc] init]; From 8081a2eb70b709d14ed9cde9dd44e589dd5114c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Antonio=20Espi=CC=81n=20Mora?= Date: Fri, 29 Apr 2016 18:20:22 +0200 Subject: [PATCH 4/5] Added more examples with horizontal buttons. Fixed some issues with constraints and the scroll view. --- .../Base.lproj/Storyboard.storyboard | 389 ++++++++++-------- SCLAlertViewExample/ViewController.h | 3 + SCLAlertViewExample/ViewController.m | 121 ++++++ 3 files changed, 332 insertions(+), 181 deletions(-) diff --git a/SCLAlertViewExample/Base.lproj/Storyboard.storyboard b/SCLAlertViewExample/Base.lproj/Storyboard.storyboard index f788db6..575a677 100644 --- a/SCLAlertViewExample/Base.lproj/Storyboard.storyboard +++ b/SCLAlertViewExample/Base.lproj/Storyboard.storyboard @@ -14,200 +14,227 @@ - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + diff --git a/SCLAlertViewExample/ViewController.h b/SCLAlertViewExample/ViewController.h index 4ba5548..8aff9e1 100644 --- a/SCLAlertViewExample/ViewController.h +++ b/SCLAlertViewExample/ViewController.h @@ -17,8 +17,11 @@ - (IBAction)showWarning:(id)sender; - (IBAction)showInfo:(id)sender; - (IBAction)showEdit:(id)sender; +- (IBAction)showEditWithHorizontalButtons:(id)sender; +- (IBAction)ShowAdvancedWithHorizontalButtons:(id)sender; - (IBAction)showCustom:(id)sender; - (IBAction)showValidation:(id)sender; +- (IBAction)showValidationWithHorizontalButtons:(id)sender; - (IBAction)showWaiting:(id)sender; @end diff --git a/SCLAlertViewExample/ViewController.m b/SCLAlertViewExample/ViewController.m index 4a7bef9..53c2eb6 100644 --- a/SCLAlertViewExample/ViewController.m +++ b/SCLAlertViewExample/ViewController.m @@ -148,6 +148,20 @@ - (IBAction)showEdit:(id)sender [alert showEdit:self title:kInfoTitle subTitle:kSubtitle closeButtonTitle:kButtonTitle duration:0.0f]; } +- (IBAction)showEditWithHorizontalButtons:(id)sender +{ + SCLAlertView *alert = [[SCLAlertView alloc] init]; + [alert setHorizontalButtons:YES]; + + SCLTextView *textField = [alert addTextField:@"Enter your name"]; + alert.hideAnimationType = SimplyDisappear; + [alert addButton:@"Show Name" actionBlock:^(void) { + NSLog(@"Text value: %@", textField.text); + }]; + + [alert showEdit:self title:kInfoTitle subTitle:kSubtitle closeButtonTitle:kButtonTitle duration:0.0f]; +} + - (IBAction)showAdvanced:(id)sender { SCLAlertView *alert = [[SCLAlertView alloc] init]; @@ -201,6 +215,60 @@ - (IBAction)showAdvanced:(id)sender [alert showTitle:self title:@"Congratulations" subTitle:kAttributeTitle style:Success closeButtonTitle:@"Done" duration:0.0f]; } +- (IBAction)ShowAdvancedWithHorizontalButtons:(id)sender +{ + SCLAlertView *alert = [[SCLAlertView alloc] init]; + [alert setHorizontalButtons:YES]; + + alert.backgroundViewColor = [UIColor cyanColor]; + + [alert setTitleFontFamily:@"Superclarendon" withSize:20.0f]; + [alert setBodyTextFontFamily:@"TrebuchetMS" withSize:14.0f]; + [alert setButtonsTextFontFamily:@"Baskerville" withSize:14.0f]; + + [alert addButton:@"First Button" target:self selector:@selector(firstButton)]; + + [alert addButton:@"Second Button" actionBlock:^(void) { + NSLog(@"Second button tapped"); + }]; + + SCLTextView *textField = [alert addTextField:@"Enter your name"]; + + [alert addButton:@"Show Name" actionBlock:^(void) { + NSLog(@"Text value: %@", textField.text); + }]; + + alert.completeButtonFormatBlock = ^NSDictionary* (void) + { + NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init]; + + buttonConfig[@"backgroundColor"] = [UIColor greenColor]; + buttonConfig[@"borderColor"] = [UIColor blackColor]; + buttonConfig[@"borderWidth"] = @"1.0f"; + buttonConfig[@"textColor"] = [UIColor blackColor]; + + return buttonConfig; + }; + + alert.attributedFormatBlock = ^NSAttributedString* (NSString *value) + { + NSMutableAttributedString *subTitle = [[NSMutableAttributedString alloc]initWithString:value]; + + NSRange redRange = [value rangeOfString:@"Attributed" options:NSCaseInsensitiveSearch]; + [subTitle addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange]; + + NSRange greenRange = [value rangeOfString:@"successfully" options:NSCaseInsensitiveSearch]; + [subTitle addAttribute:NSForegroundColorAttributeName value:[UIColor brownColor] range:greenRange]; + + NSRange underline = [value rangeOfString:@"completed" options:NSCaseInsensitiveSearch]; + [subTitle addAttributes:@{NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle)} range:underline]; + + return subTitle; + }; + + [alert showTitle:self title:@"Congratulations" subTitle:kAttributeTitle style:Success closeButtonTitle:@"Done" duration:0.0f]; +} + - (IBAction)showWithDuration:(id)sender { SCLAlertView *alert = [[SCLAlertView alloc] init]; @@ -268,6 +336,59 @@ - (IBAction)showValidation:(id)sender [alert showEdit:self title:@"Validation" subTitle:@"Ensure the data is correct before dismissing!" closeButtonTitle:@"Cancel" duration:0]; } +- (IBAction)showValidationWithHorizontalButtons:(id)sender +{ + SCLAlertView *alert = [[SCLAlertView alloc] init]; + [alert setHorizontalButtons:YES]; + + SCLTextView *evenField = [alert addTextField:@"Enter an even number"]; + evenField.keyboardType = UIKeyboardTypeNumberPad; + + SCLTextView *oddField = [alert addTextField:@"Enter an odd number"]; + oddField.keyboardType = UIKeyboardTypeNumberPad; + + [alert addButton:@"Test Validation" validationBlock:^BOOL{ + if (evenField.text.length == 0) + { + [[[UIAlertView alloc] initWithTitle:@"Whoops!" message:@"You forgot to add an even number." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; + [evenField becomeFirstResponder]; + return NO; + } + + if (oddField.text.length == 0) + { + [[[UIAlertView alloc] initWithTitle:@"Whoops!" message:@"You forgot to add an odd number." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; + [oddField becomeFirstResponder]; + return NO; + } + + NSInteger evenFieldEntry = (evenField.text).integerValue; + BOOL evenFieldPassedValidation = evenFieldEntry % 2 == 0; + + if (!evenFieldPassedValidation) + { + [[[UIAlertView alloc] initWithTitle:@"Whoops!" message:@"That is not an even number." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; + [evenField becomeFirstResponder]; + return NO; + } + + NSInteger oddFieldEntry = (oddField.text).integerValue; + BOOL oddFieldPassedValidation = oddFieldEntry % 2 == 1; + + if (!oddFieldPassedValidation) + { + [[[UIAlertView alloc] initWithTitle:@"Whoops!" message:@"That is not an odd number." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; + [oddField becomeFirstResponder]; + return NO; + } + return YES; + } actionBlock:^{ + [[[UIAlertView alloc] initWithTitle:@"Great Job!" message:@"Thanks for playing." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; + }]; + + [alert showEdit:self title:@"Validation" subTitle:@"Ensure the data is correct before dismissing!" closeButtonTitle:@"Cancel" duration:0]; +} + - (IBAction)showWaiting:(id)sender { SCLAlertView *alert = [[SCLAlertView alloc] init]; From bcc23c66d2e4def9c35bc6c724cefeadaafa159e Mon Sep 17 00:00:00 2001 From: Diogo Autilio Date: Tue, 3 May 2016 17:49:29 -0300 Subject: [PATCH 5/5] Bump version --- SCLAlertView-Objective-C.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCLAlertView-Objective-C.podspec b/SCLAlertView-Objective-C.podspec index ac40b16..1ce8100 100644 --- a/SCLAlertView-Objective-C.podspec +++ b/SCLAlertView-Objective-C.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "SCLAlertView-Objective-C" - spec.version = "1.0.2" + spec.version = "1.0.3" spec.summary = "Beautiful animated Alert View. Written in Swift but ported to Objective-C" spec.homepage = "https://github.com/dogo/SCLAlertView" spec.screenshots = "https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot.png", "https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot2.png"