{"id":15481568,"url":"https://github.com/huangxianhui001/adalertcontroller","last_synced_at":"2025-04-22T15:24:58.220Z","repository":{"id":56900204,"uuid":"238502171","full_name":"huangxianhui001/ADAlertController","owner":"huangxianhui001","description":"与 UIAlertController 类似风格的 UI 控件,包含 Alert 和 ActionSheet 以及无边距的 ActionSheet 类型.支持添加自定义视图元素,多种AlertAction可供选择,并容易扩展实现新的 AlertAction UI样式,支持优先级队列","archived":false,"fork":false,"pushed_at":"2020-03-06T16:15:02.000Z","size":37220,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-19T05:15:23.225Z","etag":null,"topics":["actionsheet","alertaction","alertview","contentview","ios","objective-c","priorityqueue","uialertcontroller"],"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/huangxianhui001.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}},"created_at":"2020-02-05T16:57:23.000Z","updated_at":"2023-10-27T03:11:18.000Z","dependencies_parsed_at":"2022-08-20T18:20:51.630Z","dependency_job_id":null,"html_url":"https://github.com/huangxianhui001/ADAlertController","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huangxianhui001%2FADAlertController","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huangxianhui001%2FADAlertController/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huangxianhui001%2FADAlertController/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huangxianhui001%2FADAlertController/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huangxianhui001","download_url":"https://codeload.github.com/huangxianhui001/ADAlertController/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250265824,"owners_count":21402178,"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","alertaction","alertview","contentview","ios","objective-c","priorityqueue","uialertcontroller"],"created_at":"2024-10-02T05:04:57.086Z","updated_at":"2025-04-22T15:24:58.185Z","avatar_url":"https://github.com/huangxianhui001.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 说明\n\n`ADAlertController` 是一个与` UIAlertController` 类似风格的 UI 控件,包含 `Alert` 和 `ActionSheet` 以及`无边距的 ActionSheet(ADAlertControllerStyleSheet)` 等 UI类型.与`UIAlertController` 有相似的 API.支持 iOS9+.并支持以下扩展功能:\n\n- 支持添加自定义视图元素\n- 多种`AlertAction`可供选择,并容易扩展实现新的 `AlertAction` UI样式\n- 支持优先级队列,在优先级队列里可配置以下功能\n  - 支持仅在某些特定的控制器上显示\n  - 支持设置黑名单\n\n## 演示\n\n![Demo 1](images/demo-01.gif)\n\n![Demo 2](images/demo-02.gif)\n\n![Demo 3](images/demo-03.gif)\n\n![Demo 4](images/demo-04.gif)\n\n![Demo 5](images/demo-05.gif)\n\n![Demo 6](images/demo-06.gif)\n\n## 安装\n\n1. 使用`CocoaPods`:\n\n   在`Podfile`中添加以下语句\n\n   `pod ‘ADAlertController’`\n\n2. 手动安装:\n\n   下载仓库代码,将`ADAlertController`文件夹下所有的文件拖到你的项目工程中\n\n   PS:`ADCustomAlertContentView`文件夹并非`ADAlertController`要求的源码,而是实现自定义内容视图的一点建议.若有其他更好的用法,欢迎提供意见.\n\n**若在使用过程中有任何问题,欢迎提`Issue`**\n\n## 使用\n\n针对演示图片中的第一张图出现的第一个例子为例,初始化代码如下:\n\n```objc\n\t\tADAlertAction *cancelAction = [ADAlertAction actionWithTitle:@\"取消\" style:ADActionStyleCancel handler:^(__kindof ADAlertAction * _Nonnull action) {\n        NSLog(@\"点击了取消\");\n    }];\n    \n    ADAlertAction *sureAction = [ADAlertAction actionWithTitle:@\"确定\" style:ADActionStyleDefault handler:^(__kindof ADAlertAction * _Nonnull action) {\n        NSLog(@\"点击了确定\");\n    }];\n    \n    ADAlertController *alertView = [[ADAlertController alloc] initWithOptions:nil title:@\"这里是标题\" message:nil actions:@[cancelAction,sureAction]];\n    [alertView show];\n    \n```\n\n\n\n### 1.初始化\n\n`ADAlertController`使用指定构造方法来生成实例:`-initWithOptions:title:message:actions:`.\n\n- 第一个参数是`ADAlertControllerConfiguration`对象类型,可以为 nil.\n\n  `ADAlertControllerConfiguration`用来配置一些 UI 样式.其中的`preferredStyle`属性就是来指定具体的 UI 样式,有以下几个枚举类型:\n\n  - `ADAlertControllerStyleAlert`:与`UIAlertControllerStyleAlert`类似\n  - `ADAlertControllerStyleActionSheet`:与`UIAlertControllerStyleActionSheet`类似\n  - `ADAlertControllerStyleSheet`:与`UIAlertControllerStyleActionSheet`类似,只是左右以及底部的边距都是 0.\n\n  `preferredStyle`属性一经初始化,不得更改.\n\n  `ADAlertControllerConfiguration`使用指定构造方法`-initWithPreferredStyle:`\n\n- 第二,第三个参数分别表示标题和内容信息,可为 nil.\n\n- 第三个参数是包含的按钮,可为 nil.不同于`UIAlertController`的添加按钮方法,这里添加按钮采用数组的方式.\n\n  对于`ADAlertControllerStyleAlert`类型,这个数组的内容就是警告框最终包含的按钮.\n\n  对于`ADAlertControllerStyleActionSheet`和`ADAlertControllerStyleSheet`类型,若想添加取消按钮,不是将取消按钮放到最后一个,而是应该调用`-addActionSheetCancelAction:`来添加.\n\n### 2.按钮的初始化\n\n`ADAlertAction`是具体的按钮类,用来生成标题或者图片的按钮,标题或图片只能二选一显示,若同时配置二者,则优先显示标题.构造方法为`+ actionWithTitle:image:style:handler:configuration:`\n\n其中`handler`为点击事件回调.`configuration`为 UI 配置相关.\n\n若需要实现自己的按钮 UI 样式,可以参考`ADAlertImageAction`的实现.\n\n另外还提供了两个`ADAlertAction`的子类:\n\n- `ADAlertGroupAction`:可将多个`ADAlertAction`作为一个按钮添加,内部的各个按钮平分宽度\n- `ADScrollableGroupAction`:`ADAlertGroupAction`的子类,当按钮个数多个时,可滑动显示\n\n### 3.显示与隐藏\n\n显示时可直接调用`-show`方法.想主动隐藏可以调用`-hiden`方法.若想触摸背景也自动隐藏,可以设置`ADAlertControllerConfiguration`的`hidenWhenTapBackground`属性为`YES`.\n\n若想进入优先级队列,可以调用`-enqueue`\n\n#### 4.设置自定义视图\n\n设置`ADAertController`的`contentView`为你需要的`UIView`对象即可,需要自己设置高度约束.建议的方法为`[contentView.heightAnchor constraintEqualToConstant:100].active = YES`.\n\n`ADAlertControllerStyleAlert`类型时,是显示在标题之上.\n\n`ADAlertControllerStyleActionSheet`和`ADAlertControllerStyleSheet`类型时,显示在` message` 之下\n\n具体用法可参考示例中的`ADAdvertView`和`ADPickerView`\n\n### *5.alert类型添加 UITextField\n\n当为`ADAlertControllerStyleAlert`类型时可以添加`textField`.具体参考示例中的”添加输入框的警告框”\n\n**目前添加UITextField 暂未适配键盘遮挡问题**\n\n### 6.优先级及优先级队列          \n\n若需要显示多个`AlertController`又难以管理各个`AlertController`的显示顺序时,可以设置优先级属性`alertPriority`并调用入队列方法`-enqueue`.在内部有个优先级队列管理对象(`ADAlertControllerPriorityQueue`)会自动管理下一个将要显示的`AlertController`对象\n\n使用优先级队列有以下注意点:\n\n1. `alertPriority`是`NSUInteger`类型,虽只有三个枚举值,但可以设置任何有效的`NSUInteger`值.\n2. 支持设置全局的黑名单.黑名单仅支持类型,不支持具体到某个控制器实例,具体参考示例中的\"黑名单时不显示”\n3. 支持设置`AlertController`仅针对某个目标控制器显示.具体参考示例中的\"指定在某个控制器显示”\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuangxianhui001%2Fadalertcontroller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuangxianhui001%2Fadalertcontroller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuangxianhui001%2Fadalertcontroller/lists"}