ZZCustomAlertView 0.1.0

ZZCustomAlertView 0.1.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2015年6月

zzdjk6 维护。




  • zzdjk6

使用

要运行示例项目,请克隆仓库,并在 Example 目录中首先运行 pod install

以下是一个简要介绍。

要生成并显示一个新的普通 ZZCustomAlertView,请编写以下代码:

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

上面的代码给你一个如下所示的警告视图,你可以点击任何地方来关闭它。

ZZCustomAlertView Plain

请记住,您应该始终提供 parentView。如果您不提供 contentView,它将生成一个默认的普通视图。

要生成一个定制的 ZZCustomAlertView,以下是一个例子

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];

上面的代码给您一个带有单个图像按钮的警告视图,带有模糊的背景,如下所示。

ZZCustomeAlertView Customized

有一些参数可以用来定制 ZZCustomAlertView,请查看头文件,您可以通过详细的注释获取所有这些参数。

/** 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;

还有一些用于显示和关闭 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;

通过调用

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

要求

  • iOS 8 SDK
  • 使用 ARC

安装

ZZCustomAlertView 通过 CocoaPods 提供使用。要安装它,只需将以下行添加到您的 Podfile 中。

pod "ZZCustomAlertView"

作者

zzdjk6, [email protected]

许可证

ZZCustomAlertView 可在 MIT 许可下获得。有关更多信息,请参阅 LICENSE 文件。