SugarAlert 0.0.1

SugarAlert 0.0.1

Globak Maxim 维护。



  • Maxim

Alert

UIAlertController 的语法糖

Beautiful API 的 UIAlertController

Alert(title: "Info", message: "Wow")
.button("Ok") { print("Ok") }
.cancel("Cancel")
.show()

.button()

它具有可选的样式和闭包参数。

参数

  • title: String
  • action: (() -> Void)?
如何使用

添加具有默认样式和空操作的空白按钮

.button("Empty button")
每种样式都有自己的功能

对于常见的.default样式

.button("Ok") { print("Ok button pressed") }

...对于.cancel

.cancel("Cancel")

.destructive

.destructive("Delete") { print("Delete") }

`.show()`

在所有地方显示您的警报

这个函数在顶层视图控制器中查找并显示警报控制器

参数

  • viewController: UIViewController?
  • animated: Bool
  • completion: (() -> Void)?

默认参数

  • viewController = nil
  • animated = true
  • completion = nil
如何使用

最常见的用法

.show()

如果想在当前viewController上显示警报,p.s. 这种方式可以节省寻找顶层viewController的时间

.show(on: self)
.show(on:self, animated: false)
.show(on:self, animated: false) { print("Poof") }