对UIAlertController
的简单扩展,因为有时您只想说“确定”。
UIAlertController
非常好用,但有时它显得过于复杂。您想有多少次只是想用一个消息和一个“确定”按钮简单地警告用户?使用 UIAlertView
似乎很容易,但使用 UIAlertController
则非常麻烦,然而使用 HEAlert
则非常简单。
这就是为什么我创建了 HEAlert
。
从
let alertView = UIAlertView(title: "Hello World", message: nil, delegate: nil, cancelButtonTitle: "OK")
alertView.show()
或
let alertController = UIAlertController(title: "Hello World", message: nil, preferredStyle: .Alert)
let action = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(action)
self.presentViewController(alertController, animated: true, completion: nil)
变到
HEAlert.ok("Hello World")
或
HEAlert.ok("Hello World", presentingViewController: self)
从v0.5开始,HEAlert
升级到了Swift 2和Xcode 7。如果您仍然需要Xcode 6.x (Swift 1.2)的支持,您可以使用HEAlert
老版本,例如v0.4.2。
当前支持通过简单的源代码添加、通过git子模块或通过CocoaPods(推荐)进行安装。
您可以直接将git作为子模块,并将HEAlert.swift
添加到您的项目中,然后开始使用!
使用方法非常简单,代码也得到了全面的文档。还有一个示例应用程序,演示了该类的基本使用。
HEAlert.ok("Hello World")
或
HEAlert.ok("Hello World", presentingViewController: self)
HEAlert.ok("Hello World", message: "This is my first HEAlert", presentingViewController: self)
您可以定制度化的部分HEAlert
行为。
HEAlert.other("Do you like waffles?", message: "This is an important question", buttonTitle: "Yes", cancelTitle: "No", presentingViewController: self, cancelHandler: { (_) -> Void in
println("Must like pancakes instead")
}) { (_) -> Void in
println("Get the syrup!")
}
NSError
轻松显示一个NSError
HEAlert.error(anNSError, presentingViewController: self, buttonHandler: nil)
参阅包含的 CHANGELOG.md
文件。
BSD 3-clause “New” 或 “Revised” License. 请参阅包含的“许可”文件。