ZZCustomAlertView 0.1.0

ZZCustomAlertView 0.1.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Jun 2015

Maintained by zzdjk6.




  • By
  • zzdjk6

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Here is a brief introduction.

To generate and show a new plain ZZCustomAlertView, write:

ZZCustomAlertView *alert = [ZZCustomAlertView alertViewWithParentView:self.view andContentView:nil];
[alert show];

The code above give you an alert view like bellow, you can tap anywhere to dismiss it.

ZZCustomAlertView Plain

Remember you should always give it a parentView. If you don't give it a contentView, it will generate a plain default one.

To generate a customized ZZCustomAlertView, there is an example:

UIImage *img = [UIImage imageNamed:@"Perfect Button"];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, img.size.width, img.size.height);
[btn setImage:img forState:UIControlStateNormal];
[btn addTarget:self action:@selector(customButtonPressed) forControlEvents:UIControlEventTouchUpInside];

ZZCustomAlertView *alert = [ZZCustomAlertView alertViewWithParentView:self.view andContentView:btn];
alert.shouldBlurBackground = YES;
alert.allowTapBackgroundToDismiss = NO;
alert.shadowColor = [UIColor whiteColor];
alert.shadowAlpha = 0.1f;
[alert show];

The code above just give you an alert view with a single image button, with blurred background, like bellow.

ZZCustomeAlertView Customized

There are some parameters you can use to customize ZZCustomAlertView, look at the header file and you can get all of them with detail comment.

/** If set to YES, the background will be blured, using iOS 8 VisualEffect, default is NO. */
@property(nonatomic, assign) BOOL shouldBlurBackground;

/** If set to YES, tap anywhere on the alert view (include background) will dismiss the alert view, default is YES. */
@property(nonatomic, assign) BOOL allowTapBackgroundToDismiss;

/** the alpha of the modal shadow, default is 0.3f. */
@property(nonatomic, assign) CGFloat shadowAlpha;

/** the color of the modal shadow, default is black. */
@property(nonatomic, strong) UIColor *shadowColor;

/** the content view of the alert view, you can put any view you write here. */
@property(nonatomic, strong) UIView *contentView;

/** the parent view of the alert view, you have to provide one. */
@property(nonatomic, strong) UIView *parentView;

And there are some methods to show and dismiss ZZCustomAlertView:

/**
 *  Show alert view.
 */
- (void)show;

/**
 *  Dismiss alert view.
 */
- (void)dismiss;

/**
 *  Show alert view with a block which will be executed when alert view finish show animation
 *
 *  @param completion A block which will be executed when alert view finish show animation
 */
- (void)showWithCompletionBlock:(void (^)(BOOL finished))completion;

/**
 *  Dismiss alert view with a block which will be executed when alert view finish dismiss animation
 *
 *  @param completion A block which will be executed when alert view finish dismiss animation
 */
- (void)dismissWithCompletionBlock:(void (^)(BOOL finished))completion;

You can get the alert view on present by call:

/**
 *  Get the alert view on present.
 *
 *  @return ZZCustomAlertView instance or nil.
 */
+ (instancetype)alertViewOnPresent;

Requirements

  • iOS 8 SDK
  • Use ARC

Installation

ZZCustomAlertView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "ZZCustomAlertView"

Author

zzdjk6, [email protected]

License

ZZCustomAlertView is available under the MIT license. See the LICENSE file for more info.