klAlert
示例
UIAlertController 很好,但是它意味着您需要编写几行代码,而在之前往往只需要一个调用。klAlert 是一个类,具有能够在单个调用中创建和处理现代警报结果的函数
Alert().withButtons(title: "Confirm",
msg: "Confirm an action.",
cancel: "Cancel",
buttons: ["OK"]) { (index) in
guard result == 1 else { return }
// Do the thing
}
当前版本:1.0.8
完全重构。
安装
CocoaPods
- 将以下内容添加到您的 Podfile
use_frameworks! #if this isn't already in your podfile
pod "klAlert"
- 执行
pod install
. - 享受。
文档
在我有大量时间前,请注意您可以在示例应用程序中找到至少简单的使用示例。
Alert 类的函数
func withOneButton(title: String, msg: String, btn: String)
显示一个带有一个按钮的警告框。没有完成处理程序。它 Simply 面板 tap 按钮时消失。
参数
title: 警告框顶部的标题
msg: 说明性警告文本
btn: 按钮的文本
func withButtons(title: String?, msg: String, cancel: String?, buttons: [String], handler: @escaping (_ result: Int) -> ()
显示包含一个或多个按钮的警告框。After a tap,它运行完成处理程序使用一个索引来指示哪个按钮被用户按下。按钮从上到下显示或如果只有两个从左到右。取消总是显示在底部或左边。
参数
title?: 警告框顶部的标题(可选) msg: 说明性警告文本 cancel?: "取消"按钮的文本(可选) buttons: 按钮标题的字符串数组
handler: 具有指示哪个按钮被触摸的 Int 的闭包(取消 = 0,btn1 = 1...)
func asAPopup(source: UIView?, title: String?, msg: String?, cancel: String?, buttons: [String], handler: @escaping (_ result: Int) -> ())
显示带有多个按钮的弹出警告,用户做出选择后运行完成处理程序,并返回被点击按钮的索引(取消 = 0)。参数
source?:弹出视图的原生视图(如果在iPad上显示,则为必需,否则为可选)
title?:警告顶部的大标题(可选) msg?:小的子标题(可选) cancel?:取消按钮的文本(可选) buttons:按钮标题的字符串数组
handler: 具有指示哪个按钮被触摸的 Int 的闭包(取消 = 0,btn1 = 1...)
作者
kenlaws, [email protected]
授权
klAlert遵循MIT许可证。更多详情请参阅LICENSE文件。