{"id":13696456,"url":"https://github.com/lixiang1994/LEEAlert","last_synced_at":"2025-05-03T17:31:19.973Z","repository":{"id":38359583,"uuid":"55025744","full_name":"lixiang1994/LEEAlert","owner":"lixiang1994","description":"优雅的可自定义 Alert ActionSheet","archived":false,"fork":false,"pushed_at":"2024-10-21T11:10:52.000Z","size":10408,"stargazers_count":1308,"open_issues_count":46,"forks_count":204,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-04-11T04:55:29.224Z","etag":null,"topics":["actionsheet","alert","alertview-alertviewcontroller","alertviewcontroller","custom","customalertview","demo","ios","iphone","lee","leealert","objective-c","pods"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lixiang1994.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-30T02:25:03.000Z","updated_at":"2025-03-20T09:28:40.000Z","dependencies_parsed_at":"2024-06-18T12:39:12.645Z","dependency_job_id":"299d723b-077b-4c67-b12c-3e35b68300d8","html_url":"https://github.com/lixiang1994/LEEAlert","commit_stats":{"total_commits":291,"total_committers":5,"mean_commits":58.2,"dds":"0.23711340206185572","last_synced_commit":"b1c505a0982d5360ff117ca5f3696e3c40ab1635"},"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lixiang1994%2FLEEAlert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lixiang1994%2FLEEAlert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lixiang1994%2FLEEAlert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lixiang1994%2FLEEAlert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lixiang1994","download_url":"https://codeload.github.com/lixiang1994/LEEAlert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252226711,"owners_count":21714855,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actionsheet","alert","alertview-alertviewcontroller","alertviewcontroller","custom","customalertview","demo","ios","iphone","lee","leealert","objective-c","pods"],"created_at":"2024-08-02T18:00:40.450Z","updated_at":"2025-05-03T17:31:17.821Z","avatar_url":"https://github.com/lixiang1994.png","language":"Objective-C","funding_links":[],"categories":["UI Components"],"sub_categories":[],"readme":"\n# LEEAlert - 优雅的Alert ActionSheet\n\n[![](https://img.shields.io/cocoapods/l/LEEAlert.svg)](LICENSE)\u0026nbsp;\n[![](http://img.shields.io/cocoapods/v/LEEAlert.svg?style=flat)](http://cocoapods.org/?q=LEEAlert)\u0026nbsp;\n[![](http://img.shields.io/cocoapods/p/LEEAlert.svg?style=flat)](http://cocoapods.org/?q=LEEAlert)\u0026nbsp;\n[![](https://img.shields.io/badge/support-iOS8%2B-blue.svg?style=flat)](https://www.apple.com/nl/ios/)\u0026nbsp;\n[![](https://img.shields.io/badge/Xcode-11.0-blue.svg)](https://developer.apple.com/xcode/)\u0026nbsp;\n[![](https://img.shields.io/badge/language-Objective--C-f48041.svg?style=flat)](https://www.apple.com/)\u0026nbsp;\n![Build Status](https://travis-ci.org/lixiang1994/LEEAlert.svg?branch=master)\u0026nbsp;\n![](https://img.shields.io/cocoapods/dt/LEEAlert.svg)\n\n\n\n演示\n==============\n![AlertDemo演示](https://github.com/lixiang1994/Resources/blob/master/LEEAlert/alertDemo.gif)\n![ActionSheetDemo演示](https://github.com/lixiang1994/Resources/blob/master/LEEAlert/actionSheetDemo.gif)\n\n\n特性\n==============\n - 链式语法 结构优雅\n - 支持alert类型与actionsheet类型\n - 默认样式为Apple风格 可自定义其样式\n - 支持自定义标题与内容 可动态调整其样式\n - 支持自定义视图添加 同时可设置位置类型等 自定义视图size改变时会自动适应.\n - 支持输入框添加 自动处理键盘相关的细节\n - 支持屏幕旋转适应 同时可自定义横竖屏最大宽度和高度\n - 支持自定义action添加 可动态调整其样式\n - 支持内部添加的功能项的间距范围设置等\n - 支持圆角设置 支持阴影效果设置\n - 支持队列和优先级 多个同时显示时根据优先级顺序排队弹出 添加到队列的如被高优先级覆盖 以后还会继续显示等.\n - 支持两种背景样式 1.半透明 (支持自定义透明度比例和颜色) 2.毛玻璃 (支持效果类型)\n - 支持自定义UIView动画方法\n - 支持自定义打开关闭动画样式(动画方向 渐变过渡 缩放过渡等)\n - 支持iOS13 Dark样式\n - 更多特性未来版本中将不断更新.\n\n\n用法\n==============\n\n### 概念\n\n无论是Alert还是ActionSheet 这里我把它们内部的控件分为两类 一: 功能项类型 (Item) 二: 动作类型 (Action).\n\n按照apple的风格设计 弹框分为上下两个部分 其中功能项的位置为 Header 既 头部, 而Action则在下部分.\n\n功能项一般分为4种类型  1. 标题 2. 内容(也叫Message) 3.输入框 4.自定义的视图 \n\nAction一般分为3种类型 1. 默认类型 2. 销毁类型(Destructive) 3.取消类型(Cancel)\n\n所以说 能添加的东西归根结底为两种 1. Item 2.Action  其余的都是一些设置等.\n\n\n根据上面的概念 我来简单介绍一下API的结构:\n\n所有添加的方法都是以 `LeeAddItem` 和 `LeeAddAction` 两个方法为基础进行的扩展.\n\n查看源码 可以发现 无论是 `LeeAddTitle` 还是 `LeeAddTextField` 最终都是通过 `LeeAddItem` 来实现的.\n\n也就是说整个添加的结构是以他们两个展开的 , 这个仅作为了解即可.\n\n![Layout](https://github.com/lixiang1994/LEEAlert/blob/master/Resources/layout.png)\n\n### Alert\n```\n    // 完整结构\n    [LEEAlert alert].cofing.XXXXX.XXXXX.LeeShow();\n```\n\n### ActionSheet\n```\n    // 完整结构\n    [LEEAlert actionSheet].cofing.XXXXX.XXXXX.LeeShow();\n```\n\n### 默认基础功能添加\n\n```\n    [LEEAlert alert].config\n    .LeeTitle(@\"标题\") \t\t// 添加一个标题 (默认样式)\n    .LeeContent(@\"内容\")\t\t// 添加一个标题 (默认样式)\n    .LeeAddTextField(^(UITextField *textField) {\t// 添加一个输入框 (自定义设置)\n    \t// textfield设置Block\n    })\n    .LeeCustomView(view)\t// 添加自定义的视图\n    .LeeAction(@\"默认Action\", ^{\t\t//添加一个默认类型的Action (默认样式 字体颜色为蓝色)\n    \t// 点击事件Block\n    })\n    .LeeDestructiveAction(@\"销毁Action\", ^{\t// 添加一个销毁类型的Action (默认样式 字体颜色为红色)\n    \t// 点击事件Block\n    })\n    .LeeCancelAction(@\"取消Action\", ^{\t// 添加一个取消类型的Action (默认样式 alert中为粗体 actionsheet中为最下方独立)\n    \t// 点击事件Block\n    })\n    .LeeShow(); // 最后调用Show开始显示\n```\t\n\t\n### 自定义基础功能添加\n\n```\n    [LEEAlert alert].config\n    .LeeAddTitle(^(UILabel *label) {\n        \n        // 自定义设置Block\n        \n        // 关于UILabel的设置这里不多说了\n        \n        label.text = @\"标题\";\n        \n        label.textColor = [UIColor redColor];\n    })\n    .LeeAddContent(^(UILabel *label) {\n        \n        // 自定义设置Block\n        \n        // 同标题一样\n    })\n    .LeeAddTextField(^(UITextField *textField) {\n        \n        // 自定义设置Block\n        \n        // 关于UITextField的设置你们都懂的 这里textField默认高度为40.0f 如果需要调整可直接设置frame 当然frame只有高度是有效的 其他的均无效\n        \n        textField.textColor = [UIColor redColor];\n    })\n    .LeeAddCustomView(^(LEECustomView *custom) {\n        \n        // 自定义设置Block\n        \n        // 设置视图对象\n        custom.view = view;\n        \n        // 设置自定义视图的位置类型 (包括靠左 靠右 居中 , 默认为居中)\n        custom.positionType = LEECustomViewPositionTypeLeft;\n        \n        // 设置是否自动适应宽度 (自适应宽度后 位置类型为居中)\n        custom.isAutoWidth = YES;\n    })\n    .LeeAddAction(^(LEEAction *action) {\n        \n        // 自定义设置Block\n        \n        // 关于更多属性的设置 请查看'LEEAction'类 这里不过多演示了\n        \n        action.title = @\"确认\";\n        \n        action.titleColor = [UIColor blueColor];\n    })\n    .LeeShow();\n```\n\n### 自定义相关样式\n\n```\n    [LEEAlert alert].config\n    .LeeCornerRadius(10.0f) \t//弹框圆角曲率\n    .LeeShadowOpacity(0.35f) \t//弹框阴影的不透明度 0.0 -- 1.0\n    .LeeHeaderColor([UIColor whiteColor]) \t//弹框背景颜色\n    .LeeBackGroundColor([UIColor whiteColor])\t //屏幕背景颜色\n    .LeeBackgroundStyleTranslucent(0.5f) \t//屏幕背景半透明样式 参数为透明度\n    .LeeBackgroundStyleBlur(UIBlurEffectStyleDark)\t //屏幕背景毛玻璃样式 参数为模糊处理样式类型 `UIBlurEffectStyle`\n    .LeeShow();\n```\n\n### 自定义最大宽高范围及相关间距\n\n```\n    [LEEAlert alert].config\n    .LeeHeaderInsets(UIEdgeInsetsMake(10, 10, 10, 10)) \t\t// 头部内间距设置 等于内部项的范围\n    .LeeMaxWidth(280.0f) // 设置最大宽度 (固定数值 横竖屏相同)\n    .LeeMaxHeight(400.0f) // 设置最大高度 (固定数值 横竖屏相同)\n    .LeeConfigMaxWidth(^CGFloat(LEEScreenOrientationType type, CGSize size) { \t// 设置最大宽度 (根据横竖屏类型进行设置 最大高度同理)\n        \n        if (type == LEEScreenOrientationTypeVertical) {\n            \n            // 竖屏类型\n            \n            return 280.0f;\n        }\n        \n        if (type == LEEScreenOrientationTypeHorizontal) {\n            \n            // 横屏类型\n            \n            return 400.0f;\n        }\n        \n        return 0.0f;\n    })\n    .LeeShow();\n    \n\n    [LEEAlert alert].config\n    .LeeTitle(@\"标题\")\n    .LeeItemInsets(UIEdgeInsetsMake(10, 0, 0, 0)) \t// 设置某一项的外边距范围 在哪一项后面 就是对哪一项进行设置\n    .LeeContent(@\"内容\")\n    .LeeItemInsets(UIEdgeInsetsMake(10, 0, 10, 0)) \t// 例如在设置标题后 紧接着添加一个LeeItemInsets() 就等于为这个标题设置了外边距范围  以此类推\n    .LeeShow();\n    \n    /**\n   \t LeeHeaderInsets 与 LeeItemInsets 决定了所添加的功能项的布局 可根据需求添加调整.\n    */\n```\n\n### 自定义动画时长\n\n```\n    [LEEAlert alert].config\n    .LeeOpenAnimationDuration(0.3f) // 设置打开动画时长 默认为0.3秒\n    .LeeCloseAnimationDuration(0.2f) // 设置关闭动画时长 默认为0.2秒\n    .LeeShow();\n```\n\n### 自定义动画样式\n\n```\n    [LEEAlert alert].config\n    .LeeOpenAnimationStyle(LEEAnimationStyleOrientationTop | LEEAnimationStyleFade | LEEAnimationStyleZoom) //设置打开动画样式的方向为上 以及淡入效果和缩放效果.\n    .LeeCloseAnimationStyle(LEEAnimationStyleOrientationBottom | LEEAnimationStyleFade | LEEAnimationStyleZoom) //设置关闭动画样式的方向为下 以及淡出效果和缩放效果.\n    .LeeShow();\n```\n\n### 自定义动画方法设置\n\n```\n    [LEEAlert alert].config\n    .LeeOpenAnimationConfig(^(void (^animatingBlock)(void), void (^animatedBlock)(void)) {\n        \n\t// 可自定义UIView动画方法以及参数设置\n\t\n        [UIView animateWithDuration:1.0f delay:0 usingSpringWithDamping:0.4 initialSpringVelocity:1 options:UIViewAnimationOptionAllowUserInteraction animations:^{\n                    \n            animatingBlock(); //调用动画中Block\n                    \n        } completion:^(BOOL finished) {\n                    \n            animatedBlock(); //调用动画结束Block\n        }];\n                \n    })\n    .LeeCloseAnimationConfig(^(void (^animatingBlock)(void), void (^animatedBlock)(void)) {\n                \n        [UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{\n                    \n            animatingBlock();\n                    \n        } completion:^(BOOL finished) {\n                    \n            animatedBlock();\n        }];\n                \n     })\n    .LeeShow();\n```\n\n### 队列与优先级设置\n\n```\n    [LEEAlert alert].config\n    .LeeQueue(YES)\t// 设置添加到队列 默认不添加 (添加后 处于显示状态时 如果有新的弹框显示 会将它暂时隐藏 等新的弹框显示结束 再将其显示出来)\n    .LeePriority(1) \t// 设置优先级 默认为0 按照优先级从高到低的顺序显示, 优先级相同时 优先显示最新的\n    .LeeShow();\n    /**\n    \t优先级和队列结合使用会将其特性融合 具体效果请运行demo自行调试体验\n    */\n```\n\n### 其他设置\n\n```\n    [LEEAlert alert].config\n    .LeePresentation([LEEPresentation windowLevel:UIWindowLevelAlert]) // 弹框window层级 默认UIWindowLevelAlert\n    .LeeShouldAutorotate(YES) // 是否支持自动旋转 默认为NO\n    .LeeSupportedInterfaceOrientations(UIInterfaceOrientationMaskAll) // 支持的旋转方向 默认为UIInterfaceOrientationMaskAll\n    .LeeClickHeaderClose(YES) // 点击弹框进行关闭 默认为NO\n    .LeeClickBackgroundClose(YES) // 设置点击背景进行关闭 Alert默认 NO , ActionSheet默认 YES\n    .LeeCloseComplete(^{ \n    \t// 关闭回调事件\n    })\n    .LeeShow();\n```\n\n### 关闭显示\n\n```\n    // 关闭指定标识的Alert或ActionSheet\n    [LEEAlert closeWithIdentifier:@\"xxxx\" completionBlock:^{\n        // 关闭完成\n    }];\n\n    // 关闭当前显示的Alert或ActionSheet\n    [LEEAlert closeWithCompletionBlock:^{\n    \t\n    \t// 如果在关闭后需要做一些其他操作 建议在该Block中进行\n    }];\n```\n\n\n### 注意事项\n\n- 在 AppDelegate 或 SceneDelegate 中设置主要Window: \n`[LEEAlert configMainWindow:self.window];`\n- 添加的功能项顺序会决定显示的排列顺序.\n- 当需要很复杂的样式时 如果默认提供的这些功能项无法满足, 建议将其封装成一个UIView对象 添加自定义视图来显示.\n- ActionSheet中 取消类型的Action 显示的位置与原生位置相同 处于底部独立的位置.\n- 设置最大宽度高度时如果使用`CGRectGetWidth([[UIScreen mainScreen] bounds])`这类方法 请考虑iOS8以后屏幕旋转 width和height会变化的特性.\n\n\n\n其他问题\n==============\n\n详情请查看[Issues](https://github.com/lixiang1994/LEEAlert/issues?q=is%3Aissue+is%3Aopen+label%3AQ%26A)\n\n\n安装\n==============\n\n### CocoaPods\n\n1. 将 cocoapods 更新至最新版本.\n2. 在 Podfile 中添加 `pod 'LEEAlert'`。\n3. 执行 `pod install` 或 `pod update`。\n4. 导入 `\u003cLEEAlert/LEEAlert.h\u003e`。\n\n### 手动安装\n\n1. 下载 LEEAlert 文件夹内的所有内容。\n2. 将 LEEAlert 内的源文件添加(拖放)到你的工程。\n3. 导入 `LEEAlert.h`。\n\n系统要求\n==============\n该库最低支持 `iOS 8.0` 和 `Xcode 11.0`。\n\n\n版本更新\n==============\n详情请查看[更新日志](https://github.com/lixiang1994/LEEAlert/blob/master/UPDATELOG.md)\n\n\n许可证\n==============\nLEEAlert 使用 MIT 许可证，详情见 [LICENSE](LICENSE) 文件。\n\n\n友情链接\n==============\n[高效的自动布局库 - SDAutoLayout](https://github.com/gsdios/SDAutoLayout)\n\n\n个人主页\n==============\n[我的简书](http://www.jianshu.com/users/a6da0db100c8)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flixiang1994%2FLEEAlert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flixiang1994%2FLEEAlert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flixiang1994%2FLEEAlert/lists"}