JESAlertView 2.0.7

JESAlertView 2.0.7

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Apr 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by JerryShi.



  • By
  • Jerry Shi

JESAlertView

Support Swift 3 🎉

JESAlertView is an alert view written by swift 3, support both action sheet and alert view style.

And now provide 6 styles to show your alert.

If you want to use the world of Swift 3, you need Xcode 8+.

Feature in 2.0.1

Redesign the code and APIs, now provide more convenient way to use JESAlertView than code before version 2.0.0, like SnapKit. 🎉

Screenshots

GIF GIF

Easy to use

Provide a default theme of alert view. So you can use this default theme or create a theme you like.

import JESAlertView

Before 2.0.1

// 🌟 Usage 👇
let theme = JESAlertViewTheme.defaultTheme()
let alert = JESAlertView(withTheme: theme, 
                    preferredStyle: .alert(category: .normal), 
                             title: "A customizable action sheet title.", 
                           message: "A customizable action sheet message.", 
                      cancelButton: .cancel("CANCEL"),
                 destructiveButton: .destructive("OK"), 
                      otherButtons: [.customize("Default 1",
                                   UIColor.whiteColor(),
UIColor(red: 80 / 255.0, green: 227 / 255.0, b: 194 / 255.0, alpah: 1.0))], 
                        tapClosure: { (index) in
                            print("Tapped button index is \(index)")
                    })
// Show Alert view
presentViewController(alert, animated: true, completion: nil)

After 2.0.1

self.jes.presentAlert(animated: true, { (make) in
    make.theme
        .actionSheet
        .title("Okay/Cancel")
        .message("A customizable action sheet message.")
        .cancel("Cancel")
        .destructive("OK")
        .normal([])
        .tapped({ (index) in
            print("Tapped index is \(index)")
        })
})  

With customize theme

self.jes.presentAlert(animated: true, { (make) in
    make.customize
        .theme(theme)
        .actionSheet
        .title("Okay/Cancel")
        .message("A customizable action sheet message.")
        .cancel("Cancel")
        .destructive("OK")
        .normal([])
        .tapped({ (index) in
            print("Tapped index is \(index)")
        })
})  

For more usage you can see here

Customize theme

You can create a theme to make the alert view different. Like this

Before 2.0.1

JESAlertViewTheme(overlayColor: UIColor.overlayColor,
                    titleFont: UIFont.boldSystemFontOfSize(18),
                   buttonFont: UIFont.boldSystemFontOfSize(16),
                  messageFont: UIFont.systemFontOfSize(16),
               titleTextColor: UIColor.textColor,
             messageTextColor: UIColor.textColor,
              backgroundColor: UIColor.backgroundColor,
                        shape: .Rounded(2.0))

shape

public typealias CornerRadius = CGFloat
public enum AlertShape {
    case squared
    case rounded(CornerRadius)
}

After 2.0.1

After 2.0.1, we can modify default properties like

let theme = AlertTheme.theme.backgroundColor(UIColor.black).buttonBackgroundColor(UIColor.red)
            .buttonTitleFont(UIFont.systemFont(ofSize: 14))

All the theme properties are here

var overlayColor: UIColor
var backgroundColor: UIColor

var titleFont: UIFont
var titleColor: UIColor
var messageFont: UIFont
var messageColor: UIColor

var buttonTitleFont: UIFont
var buttonTitleColor: UIColor
var buttonBackgroundColor: UIColor

var cancelButtonBackgroundColor: UIColor
var cancelButtonTitleColor: UIColor

var destructBackgroundColor: UIColor
var destructTitleColor: UIColor

var shape: AlertShape

Installation

JESAlertView is available through Cocoapods.

Add the following to you Podfile

pod 'JESAlertView', '~> 2.0.1'

New in version 1.0.1

Screenshots

GIF

Provide more style of alert view.

Usage

Before 2.0.1

let actionSheet = JESAlertView(withTheme: theme, 
                          preferredStyle: .alert(category: .success), 
                                   title: "Congratulations!", 
                                 message: "You've just displayed this awesome Pop Up View.", 
                            cancelButton: .cancel("CANCEL"), 
                            otherButtons: [.defaultStyle("Default 1"), .DefaultStyle("Default 2")], 
                              tapClosure: { (index) in              
                                print("Tapped button index is \(index)")
                 })
presentViewController(actionSheet, animated: true, completion: nil) 

Upgrade JESAlertViewStyle like

public enum JESAlertViewStyle {
    case actionSheet
    case alert(category: JESAlertViewCategory)
}

Create an enum named JESAlertViewCategory

public enum JESAlertViewCategory {
    case normal, success, failure, warning, notice, question
}

After 2.0.1

self.jes.presentAlert(animated: true, { (make) in
    make.theme
        .alert
        .success
        .title("Congratulations!")
        .message("You've just displayed this awesome Pop Up View.")
        .cancel("Cancel")
        .normal(["Default 1", "Default 2"])
        .tapped({ (index) in
            print("Index \(index)")
        })
})

Icon image from SCLAlertView

TODO

  • [ ] More animation
  • [ ] Show Custom view to window
  • [ ] More beautiful syntax
  • [x] Usage like SnapKit

License

JESAlertView is released under the MIT license. See LICENSE for details.