iOS 自定义弹窗UIAlertController

alert.jpg

ZFAlertController 是一款使用方便高度自定义的iOS弹窗控件

Github: https://github.com/ICU-Coders/ZFAlertController

Usage

使用方法完全和 UIAlertController 相同

创建一个普通弹窗

alert
ZFAlertController *alertVC = [ZFAlertController alertWithTitle:@"ZFAlertController" message:@"alertWithTitle:message:style:" style:ZFAlertControllerStyleAlert];

ZFAlertAction *ok = [ZFAlertAction actionWithTitle:@"ok" action:^{
}];
ZFAlertAction *cancel = [ZFAlertAction actionWithTitle:@"cancel" action:^{
}];

[alertVC addAction:ok];
[alertVC addAction:cancel];

[self presentViewController:alertVC animated:YES completion:nil];

创建一个带有TextFiled的弹窗(自动适应键盘)

textFiled
ZFAlertController *alertVC = [ZFAlertController alertWithTitle:@"Alert" message:@"alertWithTitle:message:style:" style:ZFAlertControllerStyleAlert];

[alertVC addTextFiledWithText:@"" placeholder:@"Input..." textFieldTextChangedCallback:^(NSString * _Nonnull text, UITextField * _Nonnull textField) {
    NSLog(@"text1:%@", text);
}];
ZFAlertAction *ok = [ZFAlertAction actionWithTitle:@"Ok" action:^{
    NSLog(@"ok");
    [self testFunc];
}];

[alertVC addAction:ok];
[self presentViewController:alertVC animated:YES completion:nil];

Action Sheet

actionSheet
ZFAlertController *alertVC = [ZFAlertController alertWithTitle:@"ActionSheet" message:@"alertWithTitle:message:style:" style:ZFAlertControllerStyleActionSheet];

ZFAlertAction *ok = [ZFAlertAction actionWithTitle:@"Ok" action:^{
}];
ZFAlertAction *cancel = [ZFAlertAction actionWithTitle:@"Cancel" action:^{
}];

[alertVC addAction:ok];
[alertVC addAction:cancel];

[self presentViewController:alertVC animated:YES completion:nil];

自定义

custom

添加各种自定义View

[alertVC addCustomView:^UIView * _Nonnull{
    UIView *customView = [[UIView alloc] init];
    [customView setBackgroundColor:[UIColor greenColor]];
    return customView;
} config:^(UIView * _Nonnull contentView, UIView * _Nonnull customView) {
    [customView setFrame:CGRectMake(contentView.frame.origin.x + 40, contentView.frame.origin.y - 40, contentView.frame.size.width - 40 * 2, 30)];
}];

添加按钮

[alertVC addCustomButton:^UIButton * _Nonnull{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
    return button;
} buttonAction:^(UIViewController * _Nonnull alert) {
    [alert dismissViewControllerAnimated:YES completion:nil];
} config:^(UIView * _Nonnull contentView, UIView * _Nonnull customView) {
    [customView setFrame:CGRectMake(CGRectGetMaxX(contentView.frame) - 44, contentView.frame.origin.y - 44 - 10, 44, 44)];
}];

如果有任何问题或建议,请告诉我.
如果觉得不错,给个赞吧🌟
谢谢

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 毛小文住的小乡村属于典型的亚热带季风气候,春暖、夏热、秋燥、冬寒。分明的四季滋养出不同的乡下野趣儿,虽然是女...
    只瞻前阅读 672评论 0 2
  • 告别一段情 分住红尘一隅 不去追问他的消息 只是起风时 风里传来他的气息 不禁泪眼朦胧 爱是个很怪的东西 一旦爱过...
    一树丁香阅读 331评论 3 26
  • Canvas 基础篇 1.它是H5新的API 什么是API ? 答:接口 广义上的意义 2.can...
    一顾SAMA阅读 385评论 0 0
  • 最厉害的武器是微笑 最强大的力量是爱。
    小鹿爱生活笔记阅读 75评论 0 0
  • 洋节盛行的今天,对于中国传统节日,我们的孩子还知道多少? 前两天与六岁的儿子聊起过年,明显感觉到他对过年毫无感情,...
    我是甘甘阅读 805评论 3 1