ZAlertView 1.0.4

ZAlertView 1.0.4

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

Thuong Nguyen 维护。



  • Thuong Nguyen

ZAlertView - 使用 Swift 编写的 AlertView

Version
License
Platform

alt text
alt text
alt text
alt text

简介

ZAlertView 是一个高度可定制的对话框(夸张,是吗?)视图,可以用作 UIAlertView 的替代品。它是用 Swift 编写的。这是我在我26岁生日时给自己的礼物。

导入

对于 Swift

  import ZAlertView

对于 Objective-C

  #import "ZAlertView-Swift.h"

用法

目前 ZAlertView 支持三种类型的对话框:警告、确认(是/否)和多项选择。也可以将文本字段添加到这些类型中的任何一种。

  public enum AlertType: Int {
    case Alert
    case Confirmation
    case MultipleChoice
  }

要创建并显示对话框,首先在文件的开始导入模块

  import ZAlertView

然后按如下方式显示对话框

  let dialog = ZAlertView()
  dialog.show()

还有更多方便的构造函数供您使用

  ZAlertView(title: "Title", message: "Message", alertType: AlertType.Alert)

  ZAlertView(title: "Title", message: "Message", closeButtonText: "Close this popup", closeButtonHandler: nil)

  ZAlertView(title: "Title", message: "Message", okButtonText: "Sure, I do", cancelButtonText: "No way")

  ZAlertView(title: "Title", message: "Message", isOkButtonLeft: false, okButtonText: "Cool, do it", cancelButtonText: "Stop it", okButtonHandler: nil, cancelButtonHandler: nil)

按钮处理程序(TouchHandler)只是一个 lambda 表达式

  (ZAlertView) -> ()

可以有很多属性让您为整个应用定义自己的样式

  public static var padding: CGFloat
  public static var innerPadding: CGFloat
  public static var cornerRadius: CGFloat
  public static var buttonHeight: CGFloat
  public static var buttonSectionExtraGap: CGFloat
  public static var textFieldHeight: CGFloat
  public static var backgroundAlpha: CGFloat
  public static var blurredBackground: Bool
  public static var showAnimation: ShowAnimation
  public static var hideAnimation: HideAnimation

  // Font
  public static var alertTitleFont: UIFont?
  public static var messageFont: UIFont?
  public static var buttonFont: UIFont?

  // Color
  public static var positiveColor: UIColor?
  public static var negativeColor: UIColor?
  public static var neutralColor: UIColor?
  public static var titleColor: UIColor?
  public static var messageColor: UIColor?
  public static var cancelTextColor: UIColor?
  public static var normalTextColor: UIColor?

  //Text field style
  public static var textFieldTextColor: UIColor?
  public static var textFieldBorderColor: UIColor?
  public static var textFieldBackgroundColor: UIColor?

也有一些基本的动画效果

  public enum ShowAnimation: Int {
    case FadeIn
    case FlyLeft
    case FlyTop
    case FlyRight
    case FlyBottom
  }

  public enum HideAnimation: Int {
    case FadeOut
    case FlyLeft
    case FlyTop
    case FlyRight
    case FlyBottom
  }

对于特定的对话框,以下是一些可定制的属性

  public var alertType: AlertType
  public var alertTitle: String?
  public var message: String?
  public var okTitle: String?
  public var cancelTitle: String?
  public var closeTitle: String?
  public var isOkButtonLeft: Bool
  public var allowTouchOutsideToDismiss: Bool
  public var width: CGFloat = ZAlertView.AlertWidth
  public var height: CGFloat = ZAlertView.AlertHeight

  // Master views
  public var backgroundView: UIView!
  public var alertView: UIView!

对于需要多个按钮的对话框,请使用 AlertType.MultipleChoice。在这种情况下,请使用方便的方法向对话框添加按钮。酷之处在于我们可以直接在这里使用十六进制颜色

  public func addButton(title: "Button", touchHandler: TouchHandler)

  public func addButton(title: "Button", color: UIColor?, titleColor: UIColor?, touchHandler: TouchHandler)

  public func addButton(title: "Button", hexColor: String, hexTitleColor: String, touchHandler: TouchHandler)

  public func addButton(title: "Button", font: UIFont, touchHandler: TouchHandler)

  public func addButton(title: "Button", font: UIFont, color: UIColor?, titleColor: UIColor?, touchHandler: TouchHandler)

类似地,我们还可以将文本字段添加到对话框中。每个文本字段都需要一个标识符以供以后操作

  public func addTextField(identifier: String, placeHolder: String)

  public func addTextField(identifier: String, placeHolder: String, isSecured: Bool)

  public func addTextField(identifier: String, placeHolder: String, keyboardType: UIKeyboardType)

  public func addTextField(identifier: String, placeHolder: String, keyboardType: UIKeyboardType, font: UIFont, padding: CGFloat, isSecured: Bool)

要获取文本字段

  public func getTextFieldWithIdentifier(identifier: String) -> UITextField?

安装

ZAlertView 通过 CocoaPods 提供。要安装,
只需将以下行添加到 Podfile 中即可

pod 'ZAlertView'

作者

Thuong Nguyen,[email protected]

许可证

ZAlertView 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。