RNAlertController
一个易于使用的用于 iOS 的 alert 框架,纯 Swift 编写。具有本地外观和动画,您可以添加更多功能到您的 alert 中。
特性
- 与 iOS 13 兼容,支持深色模式。
- 标题
- 描述消息
- 描述消息下方的横幅图像
- 带有闭包操作的多个按钮
- 选择器视图
- URL 按钮
- 复选框
要求
- iOS 9.0+
- Xcode 11.0+
- Swift 5.0
- Objective-C 2.0 (需要 ARC)
安装
通过 Cocoapods
RNAlertController 通过 CocoaPods 可用。要安装最新版本,只需将以下行添加到您的 Podfile 中:
# Swift 5.0 or later
pod 'RNAlertController'
然后运行 pod install
,您就可以使用这个框架了。
使用方法
RNAlertController 非常易于使用。以下示例展示了如何在视图控制器中创建一个包含 "确定" 按钮的简单警告框。
Swift
let alertController = RNAlertController(title: "Message", message: "This is a demo")
alertController.addButton(title: "Got It", type: .default)
alertController.present()
Objective-C
RNAlertController *alert = [[RNAlertController alloc] initWithTitle:@"Message"
message:@"This is a demo"];
[alert addButtonWithTitle:@"Got It" type:AlertButtonTypeDefault action:nil];
[alert presentOn:nil completion:nil];
当添加按钮时,您也可以指定按钮样式。
以下示例展示了如何创建一个包含消息和图像的警告框。
Swift
RNAlertController(title: "Message", message: "This is a demo")
.addButton(title: "Cancel", type: .cancel, action: nil)
.addButton(title: "Delete", type: .destructive, action: { [weak self] in
self?.performSomeAction()
})
.setBannerImage(UIImage(named: "Flag")!)
.present()
Objective-C
RNAlertController *alert = [[RNAlertController alloc] initWithTitle:@"Message"
message:@"This is a demo"];
[alert addButtonWithTitle:@"Cancel" type:AlertButtonTypeCancel action:nil];
[alert addButtonWithTitle:@"Delete" type:AlertButtonTypeDestructive action:^{
[self performSomeAction];
}];
[alert setBannerImage:[UIImage imageNamed:@"Flag"]];
[alert presentOn:self completion:nil];
文档
文档和 API 参考可在 rayhannabi.github.io/RNAlertController 找到。还请参阅 wiki 以获取详细的用法说明。
贡献
- 如果您需要帮助或想要询问一般问题,请创建一个 issue。
- 如果您发现了 bug,请创建一个 issue。
- 如果您有功能请求,请创建一个 issue。
许可证
本项目受 MIT 许可证许可。请参阅 LICENSE 文件以获取更多信息。