SwiftyAlert 1.1.0

SwiftyAlert 1.1.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2017年10月
SwiftSwift 版本3.0.2
SPM支持 SPM

TomoyaHayakawa维护。





简单的 UIAlertController 和 UIAlertView 包装器。
使 Swift 可用。

安装和设置

手动安装

要在没有依赖管理器的情况下安装 SwiftyAlert,请将 Alert.swift 添加到您的 Xcode 项目中。

如何使用

  • 添加导入
import SwiftyAlert
  • 最简单的警报
Alert(title: "AlertTitle").addOk().show(self)
  • 简单警报
Alert(title: "Alert", message: "Simple Alert.")
    .addDefault("OK")
    .show()
  • 操作表
Alert(title: "ActionSheet", style: .ActionSheet)
    .addDefault("Take Photo") { print("take phote") }
    .addDefault("Open Library") { print("open library") }
    .addDestructive("Delete") { print("delete") }
    .addCancel()
    .handlePopoverController { [weak self] controller in    //for iPad
        controller?.sourceView = self?.view
        controller?.sourceRect = sender.frame
    }
    .show()
  • 带文本框
Alert(title: "Alert", message: "Alert with TextField.")
    .addTextField { textField in
        textField.placeholder = "ID"
    }
    .addTextField { textField in
        textField.placeholder = "Password"
        textField.secureTextEntry = true
    }
    .handleTextFieldDidChange { textField, index in
        print("Index of textFields:", index, "text:", textField.text)
        if textField.text?.characters.count > 5 {
            textField.text = ""
        }
    }
    .addDefaultWithTextField("Login") { textFields in
        textFields?.forEach({ print($0.text) })
    }
    .addCancel("Back") { print("Cancelled") }
    .show() { print("Completion") }

高级

  • 更改 addOk() 和 addCancel() 的默认文本
Alert.okButtonTitle = "Go"
Alert.cancelButtonTitle = "Back"

消息

请在 Twitter 上向 @Sim_progra 报告错误。