测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2018年3月 |
SPM支持 SPM | ✗ |
由 xiaoyaogaojian 维护。
依赖 | |
RxSwift | ~> 4.0 |
RxCocoa | ~> 4.0 |
要运行示例项目,请克隆仓库,并首先从示例目录运行 pod install
。
RxAlert 通过 CocoaPods 提供。要安装
它,只需将以下行添加到您的 Podfile 中
pod 'RxAlert'
创建符合 AlertActionType
协议的操作
enum AlertAction: AlertActionType {
case cancel
case delete
case ok
var title: String {
switch self {
case .cancel:
return "Cancel"
case .delete:
return "Delete"
case .ok:
return "OK"
}
}
var style: UIAlertActionStyle {
switch self {
case .cancel:
return .cancel
case .delete:
return .destructive
case .ok:
return .default
}
}
// Optional
var isEnabled: Bool {
return true
}
}
使用 UIAlertController.rx
UIAlertController.rx
.presented(
by: self,
title: "Title",
message: "Some message",
preferredStyle: .alert,
actions: [AlertAction.ok, AlertAction.delete, AlertAction.cancel]
)
.subscribe(onNext: { action in
switch action {
case .ok: print("OK")
case .delete: print("Delete")
case .cancel: break
}
})
.disposed(by: disposeBag)
使用演示获取更多信息。
xiaoyaogaojian, [email protected]
RxAlert 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。