Easy Swift UIAlertController

Overview

EZAlertController

CocoaPods Compatible

Easy Swift UIAlertController

  • One line setup for all UIAlertControllers
  • Button action with closures instead of selectors
  • Easily customizable
  • Easy action sheets

Swift 2.0 is maintained in this branch

Usage

One Button Alert

EZAlertController.alert("Title")
EZAlertController.alert("Title", message: "Message")
EZAlertController.alert("Title", message: "Message", acceptMessage: "OK") { () -> () in
    print("cliked OK")
}

EZAlertController

Multiple Button Alerts

EZAlertController.alert("Title", message: "Message", buttons: ["First", "Second"]) { (alertAction, position) -> Void in
    if position == 0 {
        print("First button clicked")
    } else if position == 1 {
        print("Second button clicked")
    }
}

EZAlertController

// With Preferred Button Style along with all alerts in a single closure
// Here the Logout button will be red in color to show that it is a destructive action
EZAlertController.alert("Title", message: "Message", buttons: ["Cancel","Logout"], buttonsPreferredStyle:[.default, .destructive]) { (alert, position) in 
    if position == 0 {
        print("Cancel button clicked")
    } else if position == 1 {
        print("Logout button clicked")
    }
}

IMG_0920

Action Sheet

// With individual UIAlertAction objects
let firstButtonAction = UIAlertAction(title: "First Button", style: UIAlertActionStyle.Default, handler: { (UIAlertAction) -> Void in
    print("First Button pressed")
})
let secondButtonAction = UIAlertAction(title: "Second Button", style: UIAlertActionStyle.Default, handler: { (UIAlertAction) -> Void in
    print("Second Button pressed")
})

EZAlertController.actionSheet("Title", message: "message", actions: [firstButtonAction, secondButtonAction])

// With all actions in single closure
EZAlertController.actionSheet("Title", message: "Message", buttons: ["First", "Second"]) { (alertAction, position) -> Void in
    if position == 0 {
        print("First button clicked")
    } else if position == 1 {
        print("Second button clicked")
    }
}

EZAlertController

Customizable

let alertController = EZAlertController.alert("Title") // Returns UIAlertController
alertController.setValue(attributedTitle, forKey: "attributedTitle")
alertController.setValue(attributedMessage, forKey: "attributedMessage")
alertController.view.tintColor =  self.view.tintColor
...

Objective-C support

#import "ProjectName-Swift.h"

...

[EZAlertController alert:@"Title" message:@"Message"];

Requirements

  • Swift version 3.0

Installation

Install via CocoaPods

You can use CocoaPods to install EZAlertController by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!

pod 'EZAlertController', '3.2'

For current master branch

pod 'EZAlertController', :git => "https://github.com/thellimist/EZAlertController.git", :branch => 'master'

Install Manually

  • Download and drop 'EZAlertController.swift' in your project.

Improvement

  • Feel free sending pull requests.

License

  • EZAlertController is available under the MIT license. See the LICENSE file.

Keywords

swift, alert, AlertView, AlertViewController, UIAlertView, UIAlertViewController

Comments
  • Swift 3 in the works?

    Swift 3 in the works?

    Hi thellimist,

    just wondering if you're still working on this project and to upgrade it to work with Swift 3? I use your lib a lot and it's very helpful. Thanks a lot for the great work.

    opened by oliverbytes 8
  • Always receive this warning!

    Always receive this warning!

    Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController: 0x7aa4b600>)

    opened by dzpt 6
  • Using EZAlertController in Objective-C code

    Using EZAlertController in Objective-C code

    I'm wondering if it's possible to use this fabulous control in legacy Objective-C code alongside Swift classes?

    Other Swift code works fine for me, but EZAlertController is somehow not recognized

    ezalert

    P.S. Thanks for really nice and useful control!

    opened by ShadeApps 3
  • Presenting on keyWindow.rootViewController is not a good idea

    Presenting on keyWindow.rootViewController is not a good idea

    This is a very naive way to look at windows and controllers in this day and age. There are many cases where this assumption is incorrect. Another problem would be calling your alert method multiple times.

    The more correct way would be to display the alert controller on top of a clear root controller in a window of its own. Then you enter into the territory of managing multiple alerts displayed one after the other. And lo and behold, your have implemented _UIAlertControllerShimPresenter and _UIAlertControllerShimPresenterWindow, the internals of the now deprecated UIAlertView.

    opened by LeoNatan 2
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods šŸ¤“ https://github.com/CocoaPods/shared_resources/tree/master/media

    opened by ReadmeCritic 0
  • Looking for additional maintainers of this project

    Looking for additional maintainers of this project

    I've been working on different technologies lately. Keeping up with Swift's fast iterations takes a lot of my time. Let me know if you are interested in reviewing PRs, managing issues and handling releases of this project.

    Thanks

    opened by thellimist 3
  • Use optionals for message

    Use optionals for message

    What do you think about using optionals in message?

    It could look like so:

    @discardableResult open class func alert(_ title: String, message: String?) -> UIAlertController { return alert(title, message: message ?? "", acceptMessage: "OK", acceptBlock: { // Do nothing }) }

    opened by AlexGee17 3
  • ActionSheet not dismissing on tapping the view

    ActionSheet not dismissing on tapping the view

    I am using 3.1 version and when i click the window apart from action sheet the action sheet do not disappears . Also there is no cancel button on the Action Sheet.

    opened by kunalgupta1593 0
  • Gives Warning for no reason

    Gives Warning for no reason

    Every Time I use this , it gives me a warning stating that "Result of call to 'actionSheet(_:message:sourceView:buttons:tapBlock:)' is unused"

    opened by kunalgupta1593 1
Releases(3.2)
Owner
Kan Yilmaz
Kan Yilmaz
Simple UIAlertController builder class in Swift.

Kamagari Simple UIAlertController builder class in Swift. Features AlertBuilder class to simply build UIAlertController by using method chaining UIAle

Kazunobu Tasaka 78 Nov 29, 2022
A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.

Introduction Popup Dialog is a simple, customizable popup dialog written in Swift. Features Easy to use API with hardly any boilerplate code Convenien

Orderella Ltd. 3.8k Dec 20, 2022
Simple Alert View written in Swift, which can be used as a UIAlertController. (AlertController/AlertView/ActionSheet)

DOAlertController Simple Alert View written in Swift, which can be used as a UIAlertController replacement. It supports from iOS7! It is simple and ea

Daiki Okumura 406 Sep 5, 2022
A simple custom popup dialog view for iOS written in Swift. Replaces UIAlertController alert style.

A simple custom popup dialog view for iOS written in Swift. Replaces UIAlertController alert style.

donggyu 5 Jan 26, 2022
Swifty, modern UIAlertController wrapper.

Alertift Alertift.alert(title: "Alertift", message: "Alertift is swifty, modern, and awesome UIAlertController wrapper.") .action(.default("ā¤ļø"))

Suguru Kishimoto 287 Jan 7, 2023
Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...

Alerts & Pickers Advanced usage of native UIAlertController with TextField, TextView, DatePicker, PickerView, TableView, CollectionView and MapView. F

RV 5.5k Dec 22, 2022
An easier constructor for UIAlertController. Present an alert from anywhere.

ALRT An easier constructor for UIAlertController. Present an alert from anywhere like this. ALRT.create(.alert, title: "Alert?").addOK().addCancel().s

Masahiro Watanabe 97 Nov 11, 2022
PMAlertController is a great and customizable alert that can substitute UIAlertController

PMAlertController is a small library that allows you to substitute Apple's uncustomizable UIAlertController, with a beautiful and totally customizable

Paolo Musolino 2.5k Jan 3, 2023
A customizable, full-feature, lightweight iOS framework to be used instead of UIAlertController.

A customizable, full-feature, lightweight iOS framework to be used instead of UIAlertController.

Ali Samaiee 11 Jun 6, 2022
PMAlertController is a great and customizable alert that can substitute UIAlertController

PMAlertController is a small library that allows you to substitute Apple's uncustomizable UIAlertController, with a beautiful and totally customizable

Paolo Musolino 2.5k Jan 3, 2023
Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...

Alerts & Pickers Advanced usage of native UIAlertController with TextField, TextView, DatePicker, PickerView, TableView, CollectionView and MapView. F

RV 5.5k Dec 26, 2022
This is an iOS control for selecting a date using UIDatePicker in an UIAlertController like manner

RMDateSelectionViewController This framework allows you to select a date by presenting an action sheet. In addition, it allows you to add actions arro

Roland Moers 1.2k Dec 13, 2022
This is an iOS control for presenting any UIView in an UIAlertController like manner

RMActionController This framework allows you to present just any view as an action sheet. In addition, it allows you to add actions around the present

Roland Moers 542 Dec 5, 2022
This is an iOS control for selecting something using UIPickerView in an UIAlertController like manner

RMPickerViewController This framework allows you to pick something with a picker presented as an action sheet. In addition, it allows you to add actio

Roland Moers 382 Dec 19, 2022
Customizable replacement for UIAlertController

ActionSheet Customizable replacement for UIAlertController. Requirements Installation Swift Package Manager The Swift Package Manager is a tool for au

Horizontal Systems 0 Oct 6, 2022
UIAlertController with continuity.

CuckooAlert Allow multiple use of presentViewController to UIAlertController. You may be disappointed from this. Do you imagine that cuckoo spit out s

Jay Choi 5 Feb 2, 2020
Use UIAlertController like a boss.

Description Requirements Installation CocoaPods Carthage Usage License Description CatAlertController is a high level manager object that with chainin

Kcat 8 Feb 8, 2022
UIPicker inside a UIAlertController

DPPickerManager UIPicker inside a UIAlertController HOW TO USE : // Strings Picker let values = ["Value 1", "Value 2", "Value 3", "Value 4"] DPPickerM

Prioregroup.com 45 May 30, 2022
An easier constructor for UIAlertController. Present an alert from anywhere.

ALRT An easier constructor for UIAlertController. Present an alert from anywhere like this. ALRT.create(.alert, title: "Alert?").addOK().addCancel().s

Masahiro Watanabe 97 Nov 11, 2022