diff --git a/NYAlertViewController/NYAlertAction.h b/NYAlertViewController/NYAlertAction.h new file mode 100644 index 0000000..975709a --- /dev/null +++ b/NYAlertViewController/NYAlertAction.h @@ -0,0 +1,21 @@ +// +// NYAlertAction.h +// NYAlertViewDemo +// +// Created by Guillermo Saenz on 6/14/16. +// Copyright © 2016 Nealon Young. All rights reserved. +// + +#import + +@interface NYAlertAction : NSObject + ++ (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style handler:(void (^)(NYAlertAction *action))handler; + +@property (weak, nonatomic) UIButton *actionButton; +@property (nonatomic) NSString *title; +@property (nonatomic) UIAlertActionStyle style; +@property (nonatomic, strong) void (^handler)(NYAlertAction *action); +@property (nonatomic) BOOL enabled; + +@end diff --git a/NYAlertViewController/NYAlertAction.m b/NYAlertViewController/NYAlertAction.m new file mode 100644 index 0000000..318f6dd --- /dev/null +++ b/NYAlertViewController/NYAlertAction.m @@ -0,0 +1,38 @@ +// +// NYAlertAction.m +// NYAlertViewDemo +// +// Created by Guillermo Saenz on 6/14/16. +// Copyright © 2016 Nealon Young. All rights reserved. +// + +#import "NYAlertAction.h" + +@implementation NYAlertAction + ++ (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style handler:(void (^)(NYAlertAction *action))handler { + NYAlertAction *action = [[NYAlertAction alloc] init]; + action.title = title; + action.style = style; + action.handler = handler; + + return action; +} + +- (instancetype)init { + self = [super init]; + + if (self) { + _enabled = YES; + } + + return self; +} + +- (void)setEnabled:(BOOL)enabled { + _enabled = enabled; + + self.actionButton.enabled = enabled; +} + +@end diff --git a/NYAlertViewController/NYAlertView.h b/NYAlertViewController/NYAlertView.h index f220c85..3bbb382 100644 --- a/NYAlertViewController/NYAlertView.h +++ b/NYAlertViewController/NYAlertView.h @@ -43,13 +43,18 @@ typedef NS_ENUM(NSInteger, NYAlertViewButtonType) { @property (nonatomic) UIColor *destructiveButtonColor; @property (nonatomic) UIColor *destructiveButtonTitleColor; +@property (nonatomic) BOOL showButtonsAlwaysVertically; @property (nonatomic) CGFloat buttonCornerRadius; @property (nonatomic) CGFloat maximumWidth; -@property (nonatomic, readonly) UIView *alertBackgroundView; +@property (nonatomic, strong) UIView *alertBackgroundView; @property (nonatomic, readonly) NSLayoutConstraint *backgroundViewVerticalCenteringConstraint; +@property (nonatomic, assign) BOOL flexibleWidth; + +- (instancetype)initWithFrame:(CGRect)frame backgroundView:(UIView *)backgroundView; + //@property (nonatomic) NSArray *actions; @property (nonatomic) NSArray *actionButtons; diff --git a/NYAlertViewController/NYAlertView.m b/NYAlertViewController/NYAlertView.m index 227d52f..8dbdcb7 100644 --- a/NYAlertViewController/NYAlertView.m +++ b/NYAlertViewController/NYAlertView.m @@ -232,16 +232,27 @@ @interface NYAlertView () @implementation NYAlertView +- (instancetype)initWithFrame:(CGRect)frame backgroundView:(UIView *)backgroundView{ + self = [super initWithFrame:frame]; + if (self) { + self.alertBackgroundView = backgroundView; + self = [self initWithFrame:frame]; + } + return self; +} + - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.maximumWidth = 480.0f; - _alertBackgroundView = [[UIView alloc] initWithFrame:CGRectZero]; + if (!_alertBackgroundView) { + _alertBackgroundView = [[UIView alloc] initWithFrame:CGRectZero]; + self.alertBackgroundView.backgroundColor = [UIColor colorWithWhite:0.97f alpha:1.0f]; + self.alertBackgroundView.layer.cornerRadius = 6.0f; + } [self.alertBackgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; - self.alertBackgroundView.backgroundColor = [UIColor colorWithWhite:0.97f alpha:1.0f]; - self.alertBackgroundView.layer.cornerRadius = 6.0f; [self addSubview:_alertBackgroundView]; _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; @@ -288,22 +299,7 @@ - (instancetype)initWithFrame:(CGRect)frame { multiplier:1.0f constant:0.0f]]; - CGFloat alertBackgroundViewWidth = MIN(CGRectGetWidth([UIApplication sharedApplication].keyWindow.bounds), - CGRectGetHeight([UIApplication sharedApplication].keyWindow.bounds)) * 0.8f; - - if (alertBackgroundViewWidth > self.maximumWidth) { - alertBackgroundViewWidth = self.maximumWidth; - } - - _alertBackgroundWidthConstraint = [NSLayoutConstraint constraintWithItem:self.alertBackgroundView - attribute:NSLayoutAttributeWidth - relatedBy:NSLayoutRelationEqual - toItem:nil - attribute:NSLayoutAttributeNotAnAttribute - multiplier:0.0f - constant:alertBackgroundViewWidth]; - - [self addConstraint:self.alertBackgroundWidthConstraint]; + [self setFlexibleWidth:NO]; _backgroundViewVerticalCenteringConstraint = [NSLayoutConstraint constraintWithItem:self.alertBackgroundView attribute:NSLayoutAttributeCenterY @@ -361,7 +357,6 @@ - (instancetype)initWithFrame:(CGRect)frame { return self; } - // Pass through touches outside the backgroundView for the presentation controller to handle dismissal - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { for (UIView *subview in self.subviews) { @@ -373,6 +368,33 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { return NO; } +- (void)setFlexibleWidth:(BOOL)flexibleWidth { + if (flexibleWidth) { + if (_alertBackgroundWidthConstraint) { + [self removeConstraint:_alertBackgroundWidthConstraint]; + + _alertBackgroundWidthConstraint= NULL; + } + }else{ + CGFloat alertBackgroundViewWidth = MIN(CGRectGetWidth([UIApplication sharedApplication].keyWindow.bounds), + CGRectGetHeight([UIApplication sharedApplication].keyWindow.bounds)) * 0.8f; + + if (alertBackgroundViewWidth > self.maximumWidth) { + alertBackgroundViewWidth = self.maximumWidth; + } + + _alertBackgroundWidthConstraint = [NSLayoutConstraint constraintWithItem:self.alertBackgroundView + attribute:NSLayoutAttributeWidth + relatedBy:NSLayoutRelationEqual + toItem:nil + attribute:NSLayoutAttributeNotAnAttribute + multiplier:0.0f + constant:alertBackgroundViewWidth]; + + [self addConstraint:self.alertBackgroundWidthConstraint]; + } +} + - (void)setMaximumWidth:(CGFloat)maximumWidth { _maximumWidth = maximumWidth; self.alertBackgroundWidthConstraint.constant = maximumWidth; @@ -494,8 +516,8 @@ - (void)setActionButtons:(NSArray *)actionButtons { _actionButtons = actionButtons; - // If there are 2 actions, display the buttons next to each other. Otherwise, stack the buttons vertically at full width - if ([actionButtons count] == 2) { + // If there are 2 actions and showsButtonsAlwaysVertically is set to NO, display the buttons next to each other. Otherwise, stack the buttons vertically at full width + if ([actionButtons count] == 2 && !self.showButtonsAlwaysVertically) { UIButton *firstButton = actionButtons[0]; UIButton *lastButton = actionButtons[1]; diff --git a/NYAlertViewController/NYAlertViewController.h b/NYAlertViewController/NYAlertViewController.h index 88fb990..6d28ac7 100644 --- a/NYAlertViewController/NYAlertViewController.h +++ b/NYAlertViewController/NYAlertViewController.h @@ -7,16 +7,7 @@ #import -@interface NYAlertAction : NSObject - -+ (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style handler:(void (^)(NYAlertAction *action))handler; - -@property (nonatomic) NSString *title; -@property (nonatomic) UIAlertActionStyle style; -@property (nonatomic, strong) void (^handler)(NYAlertAction *action); -@property (nonatomic) BOOL enabled; - -@end +#import "NYAlertAction.h" typedef NS_ENUM(NSInteger, NYAlertViewControllerTransitionStyle) { /** Fade in the alert view */ @@ -34,6 +25,16 @@ typedef NS_ENUM(NSInteger, NYAlertViewControllerTransitionStyle) { */ + (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message; +/** + Creates an alert view controller with the specified backgroundView + */ +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil backgroundView:(UIView *)backgroundView; + +/** + Creates an alert view controller with the specified title ,message, and backgroundView + */ ++ (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message backgroundView:(UIView *)backgroundView; + /** The message displayed under the alert view's title */ @@ -44,6 +45,16 @@ typedef NS_ENUM(NSInteger, NYAlertViewControllerTransitionStyle) { */ @property (nonatomic) BOOL showsStatusBar; +/** + A Boolean value that determines whether the buttons should be stacked always vertically even if there are just two buttons +*/ +@property (nonatomic) BOOL showButtonsAlwaysVertically; + +/** + A Boolean value that determines whether the width of the alert should be flexible or not + */ +@property (nonatomic) BOOL flexibleWidth; + /** The custom view displayed in the presented alert view @@ -72,6 +83,10 @@ typedef NS_ENUM(NSInteger, NYAlertViewControllerTransitionStyle) { */ @property (nonatomic) BOOL swipeDismissalGestureEnabled; +@property (nonatomic) UIColor *dimViewColor; + +@property (nonatomic) CGFloat dimViewAlpha; + /** The background color of the alert view */ diff --git a/NYAlertViewController/NYAlertViewController.m b/NYAlertViewController/NYAlertViewController.m index 7d3e8ab..14e8673 100644 --- a/NYAlertViewController/NYAlertViewController.m +++ b/NYAlertViewController/NYAlertViewController.m @@ -9,297 +9,13 @@ #import "NYAlertView.h" -@interface NYAlertAction () - -@property (weak, nonatomic) UIButton *actionButton; - -@end - -@implementation NYAlertAction - -+ (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style handler:(void (^)(NYAlertAction *action))handler { - NYAlertAction *action = [[NYAlertAction alloc] init]; - action.title = title; - action.style = style; - action.handler = handler; - - return action; -} - -- (instancetype)init { - self = [super init]; - - if (self) { - _enabled = YES; - } - - return self; -} - -- (void)setEnabled:(BOOL)enabled { - _enabled = enabled; - - self.actionButton.enabled = enabled; -} - -@end - -@interface NYAlertViewPresentationAnimationController : NSObject - -@property NYAlertViewControllerTransitionStyle transitionStyle; -@property CGFloat duration; - -@end - -static CGFloat const kDefaultPresentationAnimationDuration = 0.7f; - -@implementation NYAlertViewPresentationAnimationController - -- (instancetype)init { - self = [super init]; - - if (self) { - self.duration = kDefaultPresentationAnimationDuration; - } - - return self; -} - -- (void)animateTransition:(id)transitionContext { - if (self.transitionStyle == NYAlertViewControllerTransitionStyleSlideFromTop || self.transitionStyle == NYAlertViewControllerTransitionStyleSlideFromBottom) { - UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; - - CGRect initialFrame = [transitionContext finalFrameForViewController:toViewController]; - - initialFrame.origin.y = self.transitionStyle == NYAlertViewControllerTransitionStyleSlideFromTop ? -(initialFrame.size.height + initialFrame.origin.y) : (initialFrame.size.height + initialFrame.origin.y); - toViewController.view.frame = initialFrame; - - [[transitionContext containerView] addSubview:toViewController.view]; - - // If we're using the slide from top transition, apply a 3D rotation effect to the alert view as it animates in - if (self.transitionStyle == NYAlertViewControllerTransitionStyleSlideFromTop) { - CATransform3D transform = CATransform3DIdentity; - transform.m34 = -1.0f / 600.0f; - transform = CATransform3DRotate(transform, M_PI_4 * 1.3f, 1.0f, 0.0f, 0.0f); - - toViewController.view.layer.zPosition = 100.0f; - toViewController.view.layer.transform = transform; - } - - [UIView animateWithDuration:[self transitionDuration:transitionContext] - delay:0.0f - usingSpringWithDamping:0.76f - initialSpringVelocity:0.2f - options:0 - animations:^{ - toViewController.view.layer.transform = CATransform3DIdentity; - toViewController.view.layer.opacity = 1.0f; - toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController]; - } - completion:^(BOOL finished) { - [transitionContext completeTransition:YES]; - }]; - } else { - UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; - - toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController]; - [[transitionContext containerView] addSubview:toViewController.view]; - - toViewController.view.layer.transform = CATransform3DMakeScale(1.2f, 1.2f, 1.2f); - toViewController.view.layer.opacity = 0.0f; - - [UIView animateWithDuration:[self transitionDuration:transitionContext] - animations:^{ - toViewController.view.layer.transform = CATransform3DIdentity; - toViewController.view.layer.opacity = 1.0f; - } - completion:^(BOOL finished) { - [transitionContext completeTransition:YES]; - }]; - } -} - -- (NSTimeInterval)transitionDuration:(id)transitionContext { - switch (self.transitionStyle) { - case NYAlertViewControllerTransitionStyleFade: - return 0.3f; - break; - - case NYAlertViewControllerTransitionStyleSlideFromTop: - case NYAlertViewControllerTransitionStyleSlideFromBottom: - return 0.6f; - } -} - -@end - -@interface NYAlertViewDismissalAnimationController : NSObject - -@property NYAlertViewControllerTransitionStyle transitionStyle; -@property CGFloat duration; - -@end - -static CGFloat const kDefaultDismissalAnimationDuration = 0.6f; - -@implementation NYAlertViewDismissalAnimationController - -- (instancetype)init { - self = [super init]; - - if (self) { - self.duration = kDefaultDismissalAnimationDuration; - } - - return self; -} - -- (void)animateTransition:(id)transitionContext { - if (self.transitionStyle == NYAlertViewControllerTransitionStyleSlideFromTop || self.transitionStyle == NYAlertViewControllerTransitionStyleSlideFromBottom) { - UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; - - CGRect finalFrame = [transitionContext finalFrameForViewController:fromViewController]; - finalFrame.origin.y = 1.2f * CGRectGetHeight([transitionContext containerView].frame); - - [UIView animateWithDuration:[self transitionDuration:transitionContext] - delay:0.0f - usingSpringWithDamping:0.8f - initialSpringVelocity:0.1f - options:0 - animations:^{ - fromViewController.view.frame = finalFrame; - } - completion:^(BOOL finished) { - [transitionContext completeTransition:YES]; - }]; - } else { - UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; - - [UIView animateWithDuration:[self transitionDuration:transitionContext] - animations:^{ - fromViewController.view.layer.opacity = 0.0f; - } - completion:^(BOOL finished) { - [transitionContext completeTransition:YES]; - }]; - } -} - -- (NSTimeInterval)transitionDuration:(id)transitionContext { - switch (self.transitionStyle) { - case NYAlertViewControllerTransitionStyleFade: - return 0.3f; - break; - - case NYAlertViewControllerTransitionStyleSlideFromTop: - case NYAlertViewControllerTransitionStyleSlideFromBottom: - return 0.6f; - }} - -@end - -@interface NYAlertViewPresentationController : UIPresentationController - -@property CGFloat presentedViewControllerHorizontalInset; -@property CGFloat presentedViewControllerVerticalInset; -@property (nonatomic) BOOL backgroundTapDismissalGestureEnabled; -@property UIView *backgroundDimmingView; - -@end - -@interface NYAlertViewPresentationController () - -- (void)tapGestureRecognized:(UITapGestureRecognizer *)gestureRecognizer; - -@end - -@implementation NYAlertViewPresentationController - -- (void)presentationTransitionWillBegin { - self.presentedViewController.view.layer.cornerRadius = 6.0f; - self.presentedViewController.view.layer.masksToBounds = YES; - - self.backgroundDimmingView = [[UIView alloc] initWithFrame:CGRectZero]; - [self.backgroundDimmingView setTranslatesAutoresizingMaskIntoConstraints:NO]; - self.backgroundDimmingView.alpha = 0.0f; - self.backgroundDimmingView.backgroundColor = [UIColor blackColor]; - [self.containerView addSubview:self.backgroundDimmingView]; - - [self.containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_backgroundDimmingView]|" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings(_backgroundDimmingView)]]; - - [self.containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_backgroundDimmingView]|" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings(_backgroundDimmingView)]]; - - UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognized:)]; - [self.backgroundDimmingView addGestureRecognizer:tapGestureRecognizer]; - - // Shrink the presenting view controller, and animate in the dark background view - id transitionCoordinator = [self.presentingViewController transitionCoordinator]; - [transitionCoordinator animateAlongsideTransition:^(id context) { - self.backgroundDimmingView.alpha = 0.7f; - } - completion:nil]; -} - -- (BOOL)shouldPresentInFullscreen { - return NO; -} - -- (BOOL)shouldRemovePresentersView { - return NO; -} - -- (void)presentationTransitionDidEnd:(BOOL)completed { - [super presentationTransitionDidEnd:completed]; - - if (!completed) { - [self.backgroundDimmingView removeFromSuperview]; - } -} - -- (void)dismissalTransitionWillBegin { - [super dismissalTransitionWillBegin]; - - id transitionCoordinator = [self.presentingViewController transitionCoordinator]; - [transitionCoordinator animateAlongsideTransition:^(id context) { - self.backgroundDimmingView.alpha = 0.0f; - - self.presentingViewController.view.transform = CGAffineTransformIdentity; - } - completion:nil]; -} - -- (void)containerViewWillLayoutSubviews { - [super containerViewWillLayoutSubviews]; - - [self presentedView].frame = [self frameOfPresentedViewInContainerView]; - self.backgroundDimmingView.frame = self.containerView.bounds; -} - -- (void)dismissalTransitionDidEnd:(BOOL)completed { - [super dismissalTransitionDidEnd:completed]; - - if (completed) { - [self.backgroundDimmingView removeFromSuperview]; - } -} - -- (void)tapGestureRecognized:(UITapGestureRecognizer *)gestureRecognizer { - if (self.backgroundTapDismissalGestureEnabled) { - [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; - } -} - -@end +#import "NYAlertViewPresentationController.h" +#import "NYAlertViewPresentationAnimationController.h" +#import "NYAlertViewDismissalAnimationController.h" @interface NYAlertViewController () -@property NYAlertView *view; +@property (nonatomic, strong) NYAlertView *view; @property UIPanGestureRecognizer *panGestureRecognizer; @property (nonatomic, strong) id transitioningDelegate; @@ -319,6 +35,14 @@ + (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)m return alertController; } ++ (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message backgroundView:(UIView *)backgroundView{ + NYAlertViewController *alertController = [[NYAlertViewController alloc] initWithNibName:nil bundle:nil backgroundView:backgroundView]; + alertController.title = title; + alertController.message = message; + + return alertController; +} + - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; @@ -329,6 +53,17 @@ - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibB return self; } +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil backgroundView:(UIView *)backgroundView{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + + if (self) { + self.view = [[NYAlertView alloc] initWithFrame:backgroundView.frame backgroundView:backgroundView]; + [self commonInit]; + } + + return self; +} + - (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; @@ -351,6 +86,9 @@ - (void)commonInit { _showsStatusBar = YES; + _dimViewColor = [UIColor blackColor]; + _dimViewAlpha = .7f; + _buttonTitleFont = [UIFont systemFontOfSize:16.0f]; _cancelButtonTitleFont = [UIFont boldSystemFontOfSize:16.0f]; _destructiveButtonTitleFont = [UIFont systemFontOfSize:16.0f]; @@ -385,6 +123,22 @@ - (BOOL)prefersStatusBarHidden { return !self.showsStatusBar; } +- (BOOL)showButtonsAlwaysVertically { + return self.view.showButtonsAlwaysVertically; +} + +- (void)setShowButtonsAlwaysVertically:(BOOL)showButtonsAlwaysVertically { + self.view.showButtonsAlwaysVertically = showButtonsAlwaysVertically; +} + +- (BOOL)flexibleWidth { + return self.view.flexibleWidth; +} + +- (void)setFlexibleWidth:(BOOL)flexibleWidth { + self.view.flexibleWidth = flexibleWidth; +} + - (CGFloat)maximumWidth { return self.view.maximumWidth; } @@ -413,7 +167,7 @@ - (void)panGestureRecognized:(UIPanGestureRecognizer *)gestureRecognizer { NYAlertViewPresentationController *presentationController = (NYAlertViewPresentationController* )self.presentationController; CGFloat windowHeight = CGRectGetHeight([UIApplication sharedApplication].keyWindow.bounds); - presentationController.backgroundDimmingView.alpha = 0.7f - (fabs([gestureRecognizer translationInView:self.view].y) / windowHeight); + presentationController.backgroundDimmingView.alpha = self.dimViewAlpha - (fabs([gestureRecognizer translationInView:self.view].y) / windowHeight); if (gestureRecognizer.state == UIGestureRecognizerStateEnded) { CGFloat verticalGestureVelocity = [gestureRecognizer velocityInView:self.view].y; @@ -451,7 +205,7 @@ - (void)panGestureRecognized:(UIPanGestureRecognizer *)gestureRecognizer { initialSpringVelocity:0.4f options:0 animations:^{ - presentationController.backgroundDimmingView.alpha = 0.7f; + presentationController.backgroundDimmingView.alpha = self.dimViewAlpha; [self.view layoutIfNeeded]; } completion:nil]; @@ -748,6 +502,8 @@ - (UIPresentationController *)presentationControllerForPresentedViewController:( sourceViewController:(UIViewController *)source { NYAlertViewPresentationController *presentationController = [[NYAlertViewPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting]; + presentationController.backgroundDimmingViewColor = self.dimViewColor; + presentationController.backgroundDimmingViewFinalAlpha = self.dimViewAlpha; presentationController.backgroundTapDismissalGestureEnabled = self.backgroundTapDismissalGestureEnabled; return presentationController; } diff --git a/NYAlertViewController/NYAlertViewDismissalAnimationController.h b/NYAlertViewController/NYAlertViewDismissalAnimationController.h new file mode 100644 index 0000000..003c31d --- /dev/null +++ b/NYAlertViewController/NYAlertViewDismissalAnimationController.h @@ -0,0 +1,18 @@ +// +// NYAlertViewDismissalAnimationController.h +// NYAlertViewDemo +// +// Created by Guillermo Saenz on 6/14/16. +// Copyright © 2016 Nealon Young. All rights reserved. +// + +#import + +#import "NYAlertViewController.h" + +@interface NYAlertViewDismissalAnimationController : NSObject + +@property NYAlertViewControllerTransitionStyle transitionStyle; +@property CGFloat duration; + +@end diff --git a/NYAlertViewController/NYAlertViewDismissalAnimationController.m b/NYAlertViewController/NYAlertViewDismissalAnimationController.m new file mode 100644 index 0000000..0212e1f --- /dev/null +++ b/NYAlertViewController/NYAlertViewDismissalAnimationController.m @@ -0,0 +1,67 @@ +// +// NYAlertViewDismissalAnimationController.m +// NYAlertViewDemo +// +// Created by Guillermo Saenz on 6/14/16. +// Copyright © 2016 Nealon Young. All rights reserved. +// + +#import "NYAlertViewDismissalAnimationController.h" + +static CGFloat const kDefaultDismissalAnimationDuration = .6f; + +@implementation NYAlertViewDismissalAnimationController + +- (instancetype)init { + self = [super init]; + + if (self) { + self.duration = kDefaultDismissalAnimationDuration; + } + + return self; +} + +- (void)animateTransition:(id)transitionContext { + if (self.transitionStyle == NYAlertViewControllerTransitionStyleSlideFromTop || self.transitionStyle == NYAlertViewControllerTransitionStyleSlideFromBottom) { + UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; + + CGRect finalFrame = [transitionContext finalFrameForViewController:fromViewController]; + finalFrame.origin.y = 1.2f * CGRectGetHeight([transitionContext containerView].frame); + + [UIView animateWithDuration:[self transitionDuration:transitionContext] + delay:0.0f + usingSpringWithDamping:0.8f + initialSpringVelocity:0.1f + options:0 + animations:^{ + fromViewController.view.frame = finalFrame; + } + completion:^(BOOL finished) { + [transitionContext completeTransition:YES]; + }]; + } else { + UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; + + [UIView animateWithDuration:[self transitionDuration:transitionContext] + animations:^{ + fromViewController.view.layer.opacity = 0.0f; + } + completion:^(BOOL finished) { + [transitionContext completeTransition:YES]; + }]; + } +} + +- (NSTimeInterval)transitionDuration:(id)transitionContext { + switch (self.transitionStyle) { + case NYAlertViewControllerTransitionStyleFade: + return 0.3f; + break; + + case NYAlertViewControllerTransitionStyleSlideFromTop: + case NYAlertViewControllerTransitionStyleSlideFromBottom: + return 0.6f; + }} + +@end diff --git a/NYAlertViewController/NYAlertViewPresentationAnimationController.h b/NYAlertViewController/NYAlertViewPresentationAnimationController.h new file mode 100644 index 0000000..d33c7cf --- /dev/null +++ b/NYAlertViewController/NYAlertViewPresentationAnimationController.h @@ -0,0 +1,18 @@ +// +// NYAlertViewPresentationAnimationController.h +// NYAlertViewDemo +// +// Created by Guillermo Saenz on 6/14/16. +// Copyright © 2016 Nealon Young. All rights reserved. +// + +#import + +#import "NYAlertViewController.h" + +@interface NYAlertViewPresentationAnimationController : NSObject + +@property NYAlertViewControllerTransitionStyle transitionStyle; +@property CGFloat duration; + +@end diff --git a/NYAlertViewController/NYAlertViewPresentationAnimationController.m b/NYAlertViewController/NYAlertViewPresentationAnimationController.m new file mode 100644 index 0000000..ef0ee37 --- /dev/null +++ b/NYAlertViewController/NYAlertViewPresentationAnimationController.m @@ -0,0 +1,91 @@ +// +// NYAlertViewPresentationAnimationController.m +// NYAlertViewDemo +// +// Created by Guillermo Saenz on 6/14/16. +// Copyright © 2016 Nealon Young. All rights reserved. +// + +#import "NYAlertViewPresentationAnimationController.h" + +static CGFloat const kDefaultPresentationAnimationDuration = 0.7f; + +@implementation NYAlertViewPresentationAnimationController + +- (instancetype)init { + self = [super init]; + + if (self) { + self.duration = kDefaultPresentationAnimationDuration; + } + + return self; +} + +- (void)animateTransition:(id)transitionContext { + if (self.transitionStyle == NYAlertViewControllerTransitionStyleSlideFromTop || self.transitionStyle == NYAlertViewControllerTransitionStyleSlideFromBottom) { + UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; + + CGRect initialFrame = [transitionContext finalFrameForViewController:toViewController]; + + initialFrame.origin.y = self.transitionStyle == NYAlertViewControllerTransitionStyleSlideFromTop ? -(initialFrame.size.height + initialFrame.origin.y) : (initialFrame.size.height + initialFrame.origin.y); + toViewController.view.frame = initialFrame; + + [[transitionContext containerView] addSubview:toViewController.view]; + + // If we're using the slide from top transition, apply a 3D rotation effect to the alert view as it animates in + if (self.transitionStyle == NYAlertViewControllerTransitionStyleSlideFromTop) { + CATransform3D transform = CATransform3DIdentity; + transform.m34 = -1.0f / 600.0f; + transform = CATransform3DRotate(transform, M_PI_4 * 1.3f, 1.0f, 0.0f, 0.0f); + + toViewController.view.layer.zPosition = 100.0f; + toViewController.view.layer.transform = transform; + } + + [UIView animateWithDuration:[self transitionDuration:transitionContext] + delay:0.0f + usingSpringWithDamping:0.76f + initialSpringVelocity:0.2f + options:0 + animations:^{ + toViewController.view.layer.transform = CATransform3DIdentity; + toViewController.view.layer.opacity = 1.0f; + toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController]; + } + completion:^(BOOL finished) { + [transitionContext completeTransition:YES]; + }]; + } else { + UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; + + toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController]; + [[transitionContext containerView] addSubview:toViewController.view]; + + toViewController.view.layer.transform = CATransform3DMakeScale(1.2f, 1.2f, 1.2f); + toViewController.view.layer.opacity = 0.0f; + + [UIView animateWithDuration:[self transitionDuration:transitionContext] + animations:^{ + toViewController.view.layer.transform = CATransform3DIdentity; + toViewController.view.layer.opacity = 1.0f; + } + completion:^(BOOL finished) { + [transitionContext completeTransition:YES]; + }]; + } +} + +- (NSTimeInterval)transitionDuration:(id)transitionContext { + switch (self.transitionStyle) { + case NYAlertViewControllerTransitionStyleFade: + return 0.3f; + break; + + case NYAlertViewControllerTransitionStyleSlideFromTop: + case NYAlertViewControllerTransitionStyleSlideFromBottom: + return 0.6f; + } +} + +@end diff --git a/NYAlertViewController/NYAlertViewPresentationController.h b/NYAlertViewController/NYAlertViewPresentationController.h new file mode 100644 index 0000000..0011afd --- /dev/null +++ b/NYAlertViewController/NYAlertViewPresentationController.h @@ -0,0 +1,21 @@ +// +// NYAlertViewPresentationController.h +// NYAlertViewDemo +// +// Created by Guillermo Saenz on 6/14/16. +// Copyright © 2016 Nealon Young. All rights reserved. +// + +#import + +@interface NYAlertViewPresentationController : UIPresentationController + +@property CGFloat presentedViewControllerHorizontalInset; +@property CGFloat presentedViewControllerVerticalInset; +@property (nonatomic) BOOL backgroundTapDismissalGestureEnabled; +@property UIView *backgroundDimmingView; + +@property UIColor *backgroundDimmingViewColor; +@property CGFloat backgroundDimmingViewFinalAlpha; + +@end diff --git a/NYAlertViewController/NYAlertViewPresentationController.m b/NYAlertViewController/NYAlertViewPresentationController.m new file mode 100644 index 0000000..d204e69 --- /dev/null +++ b/NYAlertViewController/NYAlertViewPresentationController.m @@ -0,0 +1,99 @@ +// +// NYAlertViewPresentationController.m +// NYAlertViewDemo +// +// Created by Guillermo Saenz on 6/14/16. +// Copyright © 2016 Nealon Young. All rights reserved. +// + +#import "NYAlertViewPresentationController.h" + +@interface NYAlertViewPresentationController () + +- (void)tapGestureRecognized:(UITapGestureRecognizer *)gestureRecognizer; + +@end + +@implementation NYAlertViewPresentationController + +- (void)presentationTransitionWillBegin { + self.presentedViewController.view.layer.cornerRadius = 6.0f; + self.presentedViewController.view.layer.masksToBounds = YES; + + self.backgroundDimmingView = [[UIView alloc] initWithFrame:CGRectZero]; + [self.backgroundDimmingView setTranslatesAutoresizingMaskIntoConstraints:NO]; + self.backgroundDimmingView.alpha = 0.0f; + self.backgroundDimmingView.backgroundColor = self.backgroundDimmingViewColor; + [self.containerView addSubview:self.backgroundDimmingView]; + + [self.containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_backgroundDimmingView]|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings(_backgroundDimmingView)]]; + + [self.containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_backgroundDimmingView]|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings(_backgroundDimmingView)]]; + + UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognized:)]; + [self.backgroundDimmingView addGestureRecognizer:tapGestureRecognizer]; + + // Shrink the presenting view controller, and animate in the dark background view + id transitionCoordinator = [self.presentingViewController transitionCoordinator]; + [transitionCoordinator animateAlongsideTransition:^(id context) { + self.backgroundDimmingView.alpha = self.backgroundDimmingViewFinalAlpha; + } + completion:nil]; +} + +- (BOOL)shouldPresentInFullscreen { + return NO; +} + +- (BOOL)shouldRemovePresentersView { + return NO; +} + +- (void)presentationTransitionDidEnd:(BOOL)completed { + [super presentationTransitionDidEnd:completed]; + + if (!completed) { + [self.backgroundDimmingView removeFromSuperview]; + } +} + +- (void)dismissalTransitionWillBegin { + [super dismissalTransitionWillBegin]; + + id transitionCoordinator = [self.presentingViewController transitionCoordinator]; + [transitionCoordinator animateAlongsideTransition:^(id context) { + self.backgroundDimmingView.alpha = 0.0f; + + self.presentingViewController.view.transform = CGAffineTransformIdentity; + } + completion:nil]; +} + +- (void)containerViewWillLayoutSubviews { + [super containerViewWillLayoutSubviews]; + + [self presentedView].frame = [self frameOfPresentedViewInContainerView]; + self.backgroundDimmingView.frame = self.containerView.bounds; +} + +- (void)dismissalTransitionDidEnd:(BOOL)completed { + [super dismissalTransitionDidEnd:completed]; + + if (completed) { + [self.backgroundDimmingView removeFromSuperview]; + } +} + +- (void)tapGestureRecognized:(UITapGestureRecognizer *)gestureRecognizer { + if (self.backgroundTapDismissalGestureEnabled) { + [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; + } +} + +@end diff --git a/NYAlertViewControllerDemo/NYAlertViewDemo.xcodeproj/project.pbxproj b/NYAlertViewControllerDemo/NYAlertViewDemo.xcodeproj/project.pbxproj index f70bff7..dcff42e 100644 --- a/NYAlertViewControllerDemo/NYAlertViewDemo.xcodeproj/project.pbxproj +++ b/NYAlertViewControllerDemo/NYAlertViewDemo.xcodeproj/project.pbxproj @@ -16,6 +16,10 @@ 0EF9AD811B5B15C7000C7F1D /* NYAlertViewDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EF9AD801B5B15C7000C7F1D /* NYAlertViewDemoTests.m */; }; 0EF9AD9C1B5B1785000C7F1D /* NYAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EF9AD8E1B5B1785000C7F1D /* NYAlertView.m */; }; 0EF9AD9D1B5B1785000C7F1D /* NYAlertViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EF9AD901B5B1785000C7F1D /* NYAlertViewController.m */; }; + 1100CF4C1D10AD1E00D1900A /* NYAlertViewPresentationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1100CF4B1D10AD1E00D1900A /* NYAlertViewPresentationController.m */; }; + 1100CF4F1D10ADC300D1900A /* NYAlertViewDismissalAnimationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1100CF4E1D10ADC300D1900A /* NYAlertViewDismissalAnimationController.m */; }; + 1100CF521D10AE4B00D1900A /* NYAlertViewPresentationAnimationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1100CF511D10AE4B00D1900A /* NYAlertViewPresentationAnimationController.m */; }; + 1100CF551D10AF3200D1900A /* NYAlertAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 1100CF541D10AF3200D1900A /* NYAlertAction.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -47,6 +51,14 @@ 0EF9AD8E1B5B1785000C7F1D /* NYAlertView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYAlertView.m; sourceTree = ""; }; 0EF9AD8F1B5B1785000C7F1D /* NYAlertViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NYAlertViewController.h; sourceTree = ""; }; 0EF9AD901B5B1785000C7F1D /* NYAlertViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYAlertViewController.m; sourceTree = ""; }; + 1100CF4A1D10AD1E00D1900A /* NYAlertViewPresentationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NYAlertViewPresentationController.h; sourceTree = ""; }; + 1100CF4B1D10AD1E00D1900A /* NYAlertViewPresentationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYAlertViewPresentationController.m; sourceTree = ""; }; + 1100CF4D1D10ADC300D1900A /* NYAlertViewDismissalAnimationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NYAlertViewDismissalAnimationController.h; sourceTree = ""; }; + 1100CF4E1D10ADC300D1900A /* NYAlertViewDismissalAnimationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYAlertViewDismissalAnimationController.m; sourceTree = ""; }; + 1100CF501D10AE4B00D1900A /* NYAlertViewPresentationAnimationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NYAlertViewPresentationAnimationController.h; sourceTree = ""; }; + 1100CF511D10AE4B00D1900A /* NYAlertViewPresentationAnimationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYAlertViewPresentationAnimationController.m; sourceTree = ""; }; + 1100CF531D10AF3200D1900A /* NYAlertAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NYAlertAction.h; sourceTree = ""; }; + 1100CF541D10AF3200D1900A /* NYAlertAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NYAlertAction.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -133,6 +145,14 @@ children = ( 0EF9AD8F1B5B1785000C7F1D /* NYAlertViewController.h */, 0EF9AD901B5B1785000C7F1D /* NYAlertViewController.m */, + 1100CF4A1D10AD1E00D1900A /* NYAlertViewPresentationController.h */, + 1100CF4B1D10AD1E00D1900A /* NYAlertViewPresentationController.m */, + 1100CF501D10AE4B00D1900A /* NYAlertViewPresentationAnimationController.h */, + 1100CF511D10AE4B00D1900A /* NYAlertViewPresentationAnimationController.m */, + 1100CF4D1D10ADC300D1900A /* NYAlertViewDismissalAnimationController.h */, + 1100CF4E1D10ADC300D1900A /* NYAlertViewDismissalAnimationController.m */, + 1100CF531D10AF3200D1900A /* NYAlertAction.h */, + 1100CF541D10AF3200D1900A /* NYAlertAction.m */, 0EF9AD8D1B5B1785000C7F1D /* NYAlertView.h */, 0EF9AD8E1B5B1785000C7F1D /* NYAlertView.m */, ); @@ -241,7 +261,11 @@ buildActionMask = 2147483647; files = ( 0EF9AD6D1B5B15C7000C7F1D /* DemoViewController.m in Sources */, + 1100CF521D10AE4B00D1900A /* NYAlertViewPresentationAnimationController.m in Sources */, 0EF9AD6A1B5B15C7000C7F1D /* AppDelegate.m in Sources */, + 1100CF551D10AF3200D1900A /* NYAlertAction.m in Sources */, + 1100CF4F1D10ADC300D1900A /* NYAlertViewDismissalAnimationController.m in Sources */, + 1100CF4C1D10AD1E00D1900A /* NYAlertViewPresentationController.m in Sources */, 0EF9AD671B5B15C7000C7F1D /* main.m in Sources */, 0EF9AD9C1B5B1785000C7F1D /* NYAlertView.m in Sources */, 0EF9AD9D1B5B1785000C7F1D /* NYAlertViewController.m in Sources */, @@ -372,6 +396,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/NYAlertViewDemo", @@ -393,6 +418,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/NYAlertViewDemo", diff --git a/NYAlertViewControllerDemo/NYAlertViewDemo/DemoViewController.m b/NYAlertViewControllerDemo/NYAlertViewDemo/DemoViewController.m index d0d317b..06103fd 100644 --- a/NYAlertViewControllerDemo/NYAlertViewDemo/DemoViewController.m +++ b/NYAlertViewControllerDemo/NYAlertViewDemo/DemoViewController.m @@ -59,13 +59,16 @@ - (void)showStandardAlertView { [self dismissViewControllerAnimated:YES completion:nil]; }]]; + alertController.view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"small-napkin"]]; + [self presentViewController:alertController animated:YES completion:nil]; } - (void)showCustomAlertViewWithActionCount:(NSInteger)actionCount { - NYAlertViewController *alertViewController = [[NYAlertViewController alloc] initWithNibName:nil bundle:nil]; + NYAlertViewController *alertViewController = actionCount==0?[[NYAlertViewController alloc] initWithNibName:nil bundle:nil backgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"small-napkin"]]] : [[NYAlertViewController alloc] initWithNibName:nil bundle:nil];; + alertViewController.title = NSLocalizedString(@"Example Title", nil); - alertViewController.message = NSLocalizedString(@"This alert uses the fade transition style! Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec id elit non mi porta gravida at eget metus.", nil); + alertViewController.message = NSLocalizedString(@"This alert uses the fade transition style!", nil); alertViewController.view.tintColor = self.view.tintColor; alertViewController.backgroundTapDismissalGestureEnabled = YES; @@ -97,6 +100,7 @@ - (void)showCustomAlertViewWithActionCount:(NSInteger)actionCount { - (void)showTextFieldAlertView { NYAlertViewController *alertViewController = [[NYAlertViewController alloc] initWithNibName:nil bundle:nil]; + alertViewController.title = NSLocalizedString(@"Login", nil); alertViewController.message = NSLocalizedString(@"The submit action is disabled until text is entered in both text fields", nil); @@ -216,7 +220,7 @@ - (void)showDatePickerAlertView { - (void)showLongMessageAlertView { NYAlertViewController *alertViewController = [[NYAlertViewController alloc] initWithNibName:nil bundle:nil]; - + alertViewController.title = NSLocalizedString(@"Long Message", nil); alertViewController.message = NSLocalizedString(@"This alert view uses the slide from bottom transition style!\n\nNullam id dolor id nibh ultricies vehicula ut id elit. Donec id elit non mi porta gravida at eget metus. Maecenas faucibus mollis interdum. Donec id elit non mi porta gravida at eget metus. Aenean lacinia bibendum nulla sed consectetur. Nullam id dolor id nibh ultricies vehicula ut id elit. Donec ullamcorper nulla non metus auctor fringilla. Nulla vitae elit libero, a pharetra augue. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Donec id elit non mi porta gravida at eget metus. Etiam porta sem malesuada magna mollis euismod. Curabitur blandit tempus porttitor. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec ullamcorper nulla non metus auctor fringilla. Nullam quis risus eget urna mollis ornare vel eu leo. Etiam porta sem malesuada magna mollis euismod. Maecenas faucibus mollis interdum. Maecenas sed diam eget risus varius blandit sit amet non magna.", nil); alertViewController.transitionStyle = NYAlertViewControllerTransitionStyleSlideFromBottom; @@ -233,6 +237,7 @@ - (void)showLongMessageAlertView { - (void)showCustomUIAlertView { NYAlertViewController *alertViewController = [[NYAlertViewController alloc] initWithNibName:nil bundle:nil]; + [alertViewController setFlexibleWidth:YES]; alertViewController.backgroundTapDismissalGestureEnabled = YES; alertViewController.swipeDismissalGestureEnabled = YES; @@ -247,6 +252,8 @@ - (void)showCustomUIAlertView { alertViewController.buttonTitleFont = [UIFont fontWithName:@"AvenirNext-Regular" size:alertViewController.buttonTitleFont.pointSize]; alertViewController.cancelButtonTitleFont = [UIFont fontWithName:@"AvenirNext-Medium" size:alertViewController.cancelButtonTitleFont.pointSize]; + alertViewController.showButtonsAlwaysVertically = YES; + alertViewController.alertViewBackgroundColor = [UIColor colorWithWhite:0.19f alpha:1.0f]; alertViewController.alertViewCornerRadius = 10.0f; diff --git a/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/AppIcon.appiconset/Contents.json b/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/AppIcon.appiconset/Contents.json index 36d2c80..eeea76c 100644 --- a/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/AppIcon.appiconset/Contents.json @@ -59,6 +59,11 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" } ], "info" : { diff --git a/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/Contents.json b/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/small-napkin.imageset/Contents.json b/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/small-napkin.imageset/Contents.json new file mode 100644 index 0000000..6a8d473 --- /dev/null +++ b/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/small-napkin.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "small-napkin.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "small-napkin@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "small-napkin@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/small-napkin.imageset/small-napkin.png b/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/small-napkin.imageset/small-napkin.png new file mode 100644 index 0000000..2877499 Binary files /dev/null and b/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/small-napkin.imageset/small-napkin.png differ diff --git a/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/small-napkin.imageset/small-napkin@2x.png b/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/small-napkin.imageset/small-napkin@2x.png new file mode 100644 index 0000000..4d111d2 Binary files /dev/null and b/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/small-napkin.imageset/small-napkin@2x.png differ diff --git a/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/small-napkin.imageset/small-napkin@3x.png b/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/small-napkin.imageset/small-napkin@3x.png new file mode 100644 index 0000000..53dd0d9 Binary files /dev/null and b/NYAlertViewControllerDemo/NYAlertViewDemo/Images.xcassets/small-napkin.imageset/small-napkin@3x.png differ