diff --git a/README.md b/README.md index 40aeebf..3518e8b 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,13 @@ SCLAlertView-Objective-C Animated Alert View written in Swift but ported to Objective-C, which can be used as a `UIAlertView` or `UIAlertController` replacement. [![Build Status](https://travis-ci.org/dogo/SCLAlertView.svg?branch=master)](https://travis-ci.org/dogo/SCLAlertView) +[![Cocoapods](http://img.shields.io/cocoapods/v/SCLAlertView-Objective-C.svg)](http://cocoapods.org/?q=SCLAlertView-Objective-C) ![BackgroundImage](https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot.png)_ ![BackgroundImage](https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot2.png) ![BackgroundImage](https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot3.png) ![BackgroundImage](https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot4.png) +![BackgroundImage](https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot5.png) ###Easy to use ```Objective-C @@ -97,6 +99,14 @@ UITextField *textField = [alert addTextField:@"Enter your name"]; [alert showEdit:self title:@"Edit View" subTitle:@"This alert view shows a text box" closeButtonTitle:@"Done" duration:0.0f]; ``` +###Indeterminate progress +```Objective-C +SCLAlertView *alert = [[SCLAlertView alloc] init]; + +[alert showWaiting:self title:@"Waiting..." subTitle:@"Blah de blah de blah, blah. Blah de blah de" closeButtonTitle:nil duration:5.0f]; +``` + + ###SCLAlertView properties ```Objective-C //Dismiss on tap outside (Default is NO) @@ -133,6 +143,7 @@ typedef NS_ENUM(NSInteger, SCLAlertViewStyle) Warning, Info, Edit, + Waiting, Custom }; ``` @@ -144,7 +155,9 @@ typedef NS_ENUM(NSInteger, SCLAlertViewHideAnimation) SlideOutToBottom, SlideOutToTop, SlideOutToLeft, - SlideOutToRight + SlideOutToRight, + SlideOutToCenter, + SlideOutFromCenter }; ``` ####Alert View show animation styles @@ -155,7 +168,9 @@ typedef NS_ENUM(NSInteger, SCLAlertViewShowAnimation) SlideInFromBottom, SlideInFromTop, SlideInFromLeft, - SlideInFromRight + SlideInFromRight, + SlideInFromCenter, + SlideInToCenter }; ``` diff --git a/SCLAlertView-Objective-C.podspec b/SCLAlertView-Objective-C.podspec index 452c7cd..285c648 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 = "0.3.6" + spec.version = "0.3.7" 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" diff --git a/SCLAlertView/SCLAlertView.h b/SCLAlertView/SCLAlertView.h index 79e5879..ee6fac3 100755 --- a/SCLAlertView/SCLAlertView.h +++ b/SCLAlertView/SCLAlertView.h @@ -26,6 +26,7 @@ typedef NS_ENUM(NSInteger, SCLAlertViewStyle) Warning, Info, Edit, + Waiting, Custom }; @@ -39,7 +40,9 @@ typedef NS_ENUM(NSInteger, SCLAlertViewHideAnimation) SlideOutToBottom, SlideOutToTop, SlideOutToLeft, - SlideOutToRight + SlideOutToRight, + SlideOutToCenter, + SlideOutFromCenter }; /** Alert show animation styles @@ -52,7 +55,9 @@ typedef NS_ENUM(NSInteger, SCLAlertViewShowAnimation) SlideInFromBottom, SlideInFromTop, SlideInFromLeft, - SlideInFromRight + SlideInFromRight, + SlideInFromCenter, + SlideInToCenter }; /** Alert background styles @@ -77,6 +82,12 @@ typedef NS_ENUM(NSInteger, SCLAlertViewBackground) */ @property UITextView *viewText; +/** Activity Indicator + * + * Holds the activityIndicator. + */ +@property UIActivityIndicatorView *activityIndicatorView; + /** Dismiss on tap outside * * A boolean value that determines whether to dismiss when tapping outside the SCLAlertView. @@ -142,6 +153,12 @@ typedef NS_ENUM(NSInteger, SCLAlertViewBackground) */ - (UITextField *)addTextField:(NSString *)title; +/** Set SubTitle Height + * + * @param value Height of scrollable subtitle text field. + */ +- (void)setSubTitleHeight:(CGFloat)value; + /** Add a Button with a title and a block to handle when the button is pressed. * * @param title The text displayed on the button. @@ -248,5 +265,15 @@ typedef NS_ENUM(NSInteger, SCLAlertViewBackground) */ - (void)showCustom:(UIViewController *)vc image:(UIImage *)image color:(UIColor *)color title:(NSString *)title subTitle:(NSString *)subTitle closeButtonTitle:(NSString *)closeButtonTitle duration:(NSTimeInterval)duration; +/** Show Waiting SCLAlertView with UIActityIndicator. + * + * @param vc The view controller the alert view will be displayed in. + * @param title The text displayed on the button. + * @param subTitle The subtitle text of the alert view. + * @param closeButtonTitle The text for the close button. + * @param duration The amount of time the alert will remain on screen until it is automatically dismissed. If automatic dismissal is not desired, set to 0. + */ +- (void)showWaiting:(UIViewController *)vc title:(NSString *)title subTitle:(NSString *)subTitle closeButtonTitle:(NSString *)closeButtonTitle duration:(NSTimeInterval)duration; + @end diff --git a/SCLAlertView/SCLAlertView.m b/SCLAlertView/SCLAlertView.m index 750d45b..be157f1 100755 --- a/SCLAlertView/SCLAlertView.m +++ b/SCLAlertView/SCLAlertView.m @@ -51,10 +51,14 @@ @implementation SCLAlertView CGFloat kCircleBackgroundTopPosition; CGFloat kCircleHeightBackground; CGFloat kCircleIconHeight; +CGFloat kActivityIndicatorHeight; CGFloat kWindowWidth; CGFloat kWindowHeight; CGFloat kTextHeight; +// Subtitle +CGFloat kSubTitleHeight; + // Font NSString *kDefaultFont = @"HelveticaNeue"; NSString *kButtonFont = @"HelveticaNeue-Bold"; @@ -82,8 +86,10 @@ - (instancetype)init kCircleBackgroundTopPosition = -15.0f; kCircleHeightBackground = 62.0f; kCircleIconHeight = 20.0f; + kActivityIndicatorHeight = 40.0f; kWindowWidth = 240.0f; kWindowHeight = 178.0f; + kSubTitleHeight = 90.0f; kTextHeight = 90.0f; _shouldDismissOnTapOutside = NO; _canAddObservers = YES; @@ -91,7 +97,7 @@ - (instancetype)init _hideAnimationType = FadeOut; _showAnimationType = SlideInFromTop; _backgroundType = Shadow; - + // Init _labelTitle = [[UILabel alloc] init]; _viewText = [[UITextView alloc] init]; @@ -102,6 +108,7 @@ - (instancetype)init _backgroundView = [[UIImageView alloc]initWithFrame:[self mainScreenFrame]]; _buttons = [[NSMutableArray alloc] init]; _inputs = [[NSMutableArray alloc] init]; + _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; // Add Subviews [self.view addSubview:_contentView]; @@ -109,6 +116,7 @@ - (instancetype)init [self.view addSubview:_circleView]; [_circleView addSubview:_circleIconImageView]; + [_circleView addSubview:_activityIndicatorView]; [_contentView addSubview:_labelTitle]; [_contentView addSubview:_viewText]; @@ -213,6 +221,8 @@ -(void)viewWillLayoutSubviews _circleView.frame = CGRectMake(kWindowWidth / 2 - kCircleHeight / 2, kCircleTopPosition, kCircleHeight, kCircleHeight); _circleView.layer.cornerRadius = self.circleView.frame.size.height / 2; _circleIconImageView.frame = CGRectMake(kCircleHeight / 2 - kCircleIconHeight / 2, kCircleHeight / 2 - kCircleIconHeight / 2, kCircleIconHeight, kCircleIconHeight); + _activityIndicatorView.frame =CGRectMake(kCircleHeight / 2 - kActivityIndicatorHeight / 2, kCircleHeight / 2 - kActivityIndicatorHeight / 2, kActivityIndicatorHeight, kActivityIndicatorHeight); + _labelTitle.frame = CGRectMake(12.0f, kCircleHeight / 2 + 12.0f, kWindowWidth - 24.0f, 40.0f); _viewText.frame = CGRectMake(12.0f, 74.0f, kWindowWidth - 24.0f, kTextHeight); @@ -281,6 +291,13 @@ - (void)setSoundURL:(NSURL *)soundURL _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:_soundURL error:&error]; } +#pragma mark - Subtitle Height + +- (void)setSubTitleHeight:(CGFloat)value +{ + kSubTitleHeight = value; +} + #pragma mark - TextField - (UITextField *)addTextField:(NSString *)title @@ -504,6 +521,10 @@ -(SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)imag iconImage = SCLAlertViewStyleKit.imageOfEdit; break; + case Waiting: + viewColor = UIColorFromRGB(0x6c125d); + break; + case Custom: viewColor = color; iconImage = image; @@ -531,7 +552,7 @@ -(SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)imag } // Adjust text view size, if necessary - CGSize sz = CGSizeMake(kWindowWidth - 24.0f, 90.0f); + CGSize sz = CGSizeMake(kWindowWidth - 24.0f, kSubTitleHeight); NSDictionary *attr = @{NSFontAttributeName:self.viewText.font}; if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) @@ -543,6 +564,9 @@ -(SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)imag { kWindowHeight -= (kTextHeight - ht); kTextHeight = ht; + }else{ + kWindowHeight += (ht - kTextHeight); + kTextHeight = ht; } } else @@ -554,6 +578,9 @@ -(SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)imag { kWindowHeight -= (kTextHeight - ht); kTextHeight = ht; + }else{ + kWindowHeight += (ht - kTextHeight); + kTextHeight = ht; } } } @@ -579,7 +606,13 @@ -(SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)imag // Alert view colour and images self.circleView.backgroundColor = viewColor; - self.circleIconImageView.image = iconImage; + + if (style == Waiting) { + [self.activityIndicatorView startAnimating]; + } else { + self.circleIconImageView.image = iconImage; + } + for (UITextField *textField in _inputs) { @@ -664,6 +697,11 @@ - (void)showCustom:(UIViewController *)vc image:(UIImage *)image color:(UIColor [self showTitle:vc image:image color:color title:title subTitle:subTitle duration:duration completeText:closeButtonTitle style:Custom]; } +- (void)showWaiting:(UIViewController *)vc title:(NSString *)title subTitle:(NSString *)subTitle closeButtonTitle:(NSString *)closeButtonTitle duration:(NSTimeInterval)duration +{ + [self showTitle:vc image:nil color:nil title:title subTitle:subTitle duration:duration completeText:closeButtonTitle style:Waiting]; +} + #pragma mark - Visibility - (BOOL)isVisible @@ -744,6 +782,14 @@ - (void)showView case SlideInFromRight: [self slideInFromRight]; break; + + case SlideInFromCenter: + [self slideInFromCenter]; + break; + + case SlideInToCenter: + [self slideInToCenter]; + break; } } @@ -772,7 +818,18 @@ - (void)hideView case SlideOutToRight: [self slideOutToRight]; break; + + case SlideOutToCenter: + [self slideOutToCenter]; + break; + + case SlideOutFromCenter: + [self slideOutFromCenter]; + break; } + + [_activityIndicatorView stopAnimating]; + if (self.dismissBlock) { self.dismissBlock(); @@ -837,6 +894,30 @@ - (void)slideOutToRight }]; } +- (void)slideOutToCenter +{ + [UIView animateWithDuration:0.3f animations:^{ + self.view.transform = + CGAffineTransformConcat(CGAffineTransformIdentity, + CGAffineTransformMakeScale(0.1f, 0.1f)); + self.view.alpha = 0.0f; + } completion:^(BOOL completed) { + [self fadeOut]; + }]; +} + +- (void)slideOutFromCenter +{ + [UIView animateWithDuration:0.3f animations:^{ + self.view.transform = + CGAffineTransformConcat(CGAffineTransformIdentity, + CGAffineTransformMakeScale(3.0f, 3.0f)); + self.view.alpha = 0.0f; + } completion:^(BOOL completed) { + [self fadeOut]; + }]; +} + #pragma mark - Show Animations - (void)fadeIn @@ -946,4 +1027,46 @@ - (void)slideInFromRight }]; } +- (void)slideInFromCenter +{ + //From + self.view.transform = CGAffineTransformConcat(CGAffineTransformIdentity, + CGAffineTransformMakeScale(3.0f, 3.0f)); + self.view.alpha = 0.0f; + + [UIView animateWithDuration:0.3f animations:^{ + self.backgroundView.alpha = _backgroundOpacity; + + //To + self.view.transform = CGAffineTransformConcat(CGAffineTransformIdentity, + CGAffineTransformMakeScale(1.0f, 1.0f)); + self.view.alpha = 1.0f; + } completion:^(BOOL completed) { + [UIView animateWithDuration:0.2f animations:^{ + self.view.center = _backgroundView.center; + }]; + }]; +} + +- (void)slideInToCenter +{ + //From + self.view.transform = CGAffineTransformConcat(CGAffineTransformIdentity, + CGAffineTransformMakeScale(0.1f, 0.1f)); + self.view.alpha = 0.0f; + + [UIView animateWithDuration:0.3f animations:^{ + self.backgroundView.alpha = _backgroundOpacity; + + //To + self.view.transform = CGAffineTransformConcat(CGAffineTransformIdentity, + CGAffineTransformMakeScale(1.0f, 1.0f)); + self.view.alpha = 1.0f; + } completion:^(BOOL completed) { + [UIView animateWithDuration:0.2f animations:^{ + self.view.center = _backgroundView.center; + }]; + }]; +} + @end diff --git a/SCLAlertViewExample/Base.lproj/Storyboard.storyboard b/SCLAlertViewExample/Base.lproj/Storyboard.storyboard index 7d58529..f105cfb 100644 --- a/SCLAlertViewExample/Base.lproj/Storyboard.storyboard +++ b/SCLAlertViewExample/Base.lproj/Storyboard.storyboard @@ -1,8 +1,8 @@ - + - + @@ -116,12 +116,26 @@ + + + @@ -145,7 +159,7 @@ - + diff --git a/SCLAlertViewExample/ViewController.h b/SCLAlertViewExample/ViewController.h index 764fb8a..53a20f1 100644 --- a/SCLAlertViewExample/ViewController.h +++ b/SCLAlertViewExample/ViewController.h @@ -18,6 +18,7 @@ - (IBAction)showEdit:(id)sender; - (IBAction)showCustom:(id)sender; - (IBAction)showValidation:(id)sender; +- (IBAction)showWaiting:(id)sender; @end diff --git a/SCLAlertViewExample/ViewController.m b/SCLAlertViewExample/ViewController.m index 89913d1..297c5b4 100644 --- a/SCLAlertViewExample/ViewController.m +++ b/SCLAlertViewExample/ViewController.m @@ -225,6 +225,17 @@ - (IBAction)showValidation:(id)sender [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]; + + [alert setShowAnimationType:SlideInToCenter]; + [alert setHideAnimationType:SlideOutFromCenter]; + + [alert showWaiting:self title:@"Waiting..." + subTitle:@"Blah de blah de blah, blah. Blah de blah de" + closeButtonTitle:nil duration:5.0f]; +} + - (void)firstButton { NSLog(@"First button tapped"); diff --git a/ScreenShots/ScreenShot5.png b/ScreenShots/ScreenShot5.png new file mode 100644 index 0000000..7f44e31 Binary files /dev/null and b/ScreenShots/ScreenShot5.png differ