Code Monkey home page Code Monkey logo

zalertview's Introduction

ZAlertView - AlertView written in Swift

Version License Platform

alt text alt text alt text alt text

Introduction

ZAlertView is a highly customizable dialog (exaggerated, right?) view which can be used as a substitution for UIAlertView. It's written in Swift. This is the gift I give to myself on my 26th birthday.

Import

For Swift

  import ZAlertView

For Objective-C

  #import "ZAlertView-Swift.h"

Usage

There are 3 types of dialog that ZAlertView currently supports: Alert, Confirmation (Yes/No) and Multiple choice. TextFields can also be added to any of those types.

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

To create and show a dialog, first of all, import the module at the beginning of the file:

  import ZAlertView

Then show the dialog as below:

  let dialog = ZAlertView()
  dialog.show()

There are more convenient constructors for you to use:

  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)

And button handler (TouchHandler) is just a lambda:

  (ZAlertView) -> ()

There are plenty of attributes that you can use to make your own style for the whole app:

  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?

There are also some basic animations:

  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
  }

For a specific dialog, there are customizable properties as below:

  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!

For dialogs that need multiple buttons, please use AlertType.MultipleChoice. In such case, use the convenient method to add buttons to the dialog. Cool things is that we can use hex color directly here:

  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)

Similarly, we can also add textfields to the dialog. Each textfield needs an identifier for later manipulation:

  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)

To get a textfield:

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

Installation

ZAlertView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ZAlertView'

Author

Thuong Nguyen, [email protected]

License

ZAlertView is available under the MIT license. See the LICENSE file for more info.

zalertview's People

Contributors

zelic91 avatar christianhatch avatar aybekckaya avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.