Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift

Overview

CDAlertView: Highly customizable alert popup

Carthage compatible Cocoapod CI Status Language Platform License

CDAlertView is highly customizable alert popup written in Swift. Usage is similar to UIAlertController.

Screenshots

CDAlertView Types

Animations

1 2 3

Usage

Basic usage without any buttons:

CDAlertView(title: "Awesome Title", message: "Well explained message!", type: .notification).show()

NOTE: You can use it without buttons. Touch outside of the popup or move it will disappear it if there is no action button. If there is an action button, only pressing button will disappear it.

To add new buttons:

let alert = CDAlertView(title: "Awesome Title", message: "Are you in?!", type: .notification)
let doneAction = CDAlertViewAction(title: "Sure! 💪")
alert.add(action: doneAction)
let nevermindAction = CDAlertViewAction(title: "Nevermind 😑")
alert.add(action: nevermindAction)
alert.show()

To enable text field in popup:

alert.isTextFieldHidden = false

Custom view is also supported. If you want to use custom view, you are responsible for the height of custom view. Custom view is used in UIStackView.

let myCustomView = UIVIew(frame: myFrame)
// Don't forget to handle height of `myCustomView`
alert.customView = myCustomView

CDAlertView types:

public enum CDAlertViewType {
    case error, warning, success, notification, alarm, noImage, custom(image:UIImage)
}

Initialization

Advanced Alert Initialization

To use it with your custom icon, initialize without type (or with .empty) and set your icon and background color:

let alert = CDAlertView(title: "Awesome Title", message: "Well explained message!", type: .custom(image: UIImage(named:"YourAwesomeImage")))
alert.circleFillColor = UIColor.yourAmazingColor

Hide Alert with your animation

let alert = CDAlertView(title: "Awesome Title", message: "Well explained message!", type: .success)
alert.hideAnimations = { (center, transform, alpha) in
    transform = CGAffineTransform(scaleX: 3, y: 3)
    alpha = 0
}
alert.hideAnimationDuration = 0.88
alert.show()

Hide Alert with timer

let alert = CDAlertView(title: "Awesome Title", message: "Well explained message!", type: .success)
alert.autoHideTime = 4.5 // This will hide alert box after 4.5 seconds

List of Available CDAlertView Options

titleTextColor: UIColor -> Sets title's text color

messageTextColor: UIColor -> Sets message's text color

titleFont: UIFont -> Sets title's font

messageFont: UIFont -> Sets message's font

isHeaderIconFilled: Bool -> Chooses filled icons instead of outline ones. Default is false.

alertBackgroundColor: UIColor -> Sets popup's background color.

popupWidth: CGFloat -> Width of the popup view

hasRoundedCorners: Bool -> Apply rounded corners to alert view. Default is true.

hasShadow: Bool -> Apply shadows around the popup. Defualt is true.

circleFillColor: UIColor -> Sets background color of header icon. (Color of circle area)

isActionButtonsVertical: Bool -> Alignes action buttons vertical. Default is false. Maximum number of horizontal buttons is 3.

canHideWhenTapBack -> Hide self when tapped backgroundView. Default is false.

hideAnimationDuration: TimeInterval -> Sets the animation duration of hide animation

hideAnimations: CDAlertAnimationBlock -> Sets the hiding animations depending on the center, transform and alpha values. You can create your animations by changing these values for alert popup.

If you enabled text field with setting isTextFieldHidden property to false, following properties will be available also:

textFieldFont: UIFont -> Font of textField's text

textFieldIsSecureTextEntry: Bool -> Sets the isSecureTextEntry property of UITextField

textFieldReturnKeyType: UIReturnKeyType -> Sets the returnKeyType property of UITextField

textFieldTextAlignment: NSTextAlignment -> Sets the textAlignment property of UITextField. Default is .left.

textFieldPlaceholderText: String? -> Sets the placeholder text for UITextField.

textFieldAutocapitalizationType: UITextAutocapitalizationType -> Sets the autocapitalizationType property of UITextField. Default is .none.

textFieldBackgroundColor: UIColor -> Sets UITextField's background color.

textFieldTintColor: UIColor -> Sets UITextField's tint color.

textFieldText: String? -> Sets & gets UITextField's text.

textFieldHeight: CGFloat -> Sets the height of UITextField.

textFieldDelegate: UITextViewDelegate? -> Sets the delegate of UITextField. Default delegate is CDAlertView. If you overwrite this, you're responsible for resigning the UITextField.

autoHideTime: TimeInterval? -> Sets the time interval for dismiss time. Default is nil.

Advanced action initialization:

font, textColor, backgroundColor, handler are all optional and has default parameter values. You can initilize with them or set them after initialization.

let action = CDAlertViewAction(title: "Action Title", font: UIFont.yourCustomFont, textColor: UIColor.yourTextColor, backgroundColor: UIColor.yourBackgroundColor, handler: { action in })
alertView.addAction(action)

NOTE: Aligning buttons vertical and horizontal is possible. But using more than 3 buttons in horizontal placement is not possible.

List of CDAlertViewAction Options

buttonTitle: String -> Set's the action button title

buttonTextColor: UIColor -> Sets the action button title color. Default value is RGB(27,169,225).

buttonFont: UIFont -> Sets the action button title font. Default value is UIFont.systemFont(ofSize: 17).

buttonBackgroundColor: UIColor -> Sets the background color of action button. If not set, it uses alertBackgroundColor of CDAlertView.

List of available methods

textFieldBecomeFirstResponder() -> Calls the becomeFirstResponder() method of textField if alert.isTextFieldHidden set to true. Otherwise, does nothing.

textFieldResignFirstResponder() -> Calls the resignFirstResponder() method of textField if alert.isTextFieldHidden set to true. Otherwise, does nothing.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

This library supports Swift 5. Use 0.9.1 for Swift 4.2. Use 0.6.1 for Swift 3.1.

Using CocoaPods

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

pod "CDAlertView"

Using Carthage

CDAlertView is available through Carthage. To install it, simply add the following line to your Cartfile:

github "candostdagdeviren/CDAlertView"

Requirements

  • Xcode 9
  • Swift 4
  • iOS 9.0+

Icons

Thanks to Icons8 for beautiful icons.

License

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

Comments
  • No icon bug

    No icon bug

    Hello, I really like your library and using it :) When I use it as .notification type, its background comes with blue but its icon does not appear. Here is the image from the bug. I simply use it from your USAGE part.

    whatsapp image 2017-08-01 at 6 12 22 pm

    bug good first issue 
    opened by WrathChaos 11
  • Additional customization options

    Additional customization options

    These changes do the following:

    1. Allow an action handler to prevent the alert from being dismissed. This is useful for checking the textfield for validation prior to the alert being dismissed.
    2. Added ability to set the keyboard type and auto correction type for the text field. Pretty straightforward.
    3. Added ability to turn off rounded corners. My usage requires square corners.
    4. If the top circle is clear, treat this as not showing the circle and shrink the header. My usage doesn't display the circle at the top.
    opened by sgruby 8
  • Message in alert is getting truncated

    Message in alert is getting truncated

    In my app presenting an alert but the message getting truncated to one line

    let alert = CDAlertView(title: title, message: message, type: CDAlertViewType.error)
    let okay = CDAlertViewAction(title: "OK", font: nil, textColor: nil, backgroundColor: nil) { (action) in
    }
    alert.add(action: okay)
    alert.show()
    

    screen shot 2017-11-06 at 9 16 06 pm

    opened by Kalikanth 8
  • CDAlertView play nice with IQKeyboardManager?

    CDAlertView play nice with IQKeyboardManager?

    Hello,

    I'm trying to get the IQKeyboardManager plugin (https://github.com/hackiftekhar/IQKeyboardManager) to play nicely with your great CDAlertView plugin... when the keyboard pops up, I was hoping that the AlertView popup would shift up alittle to provide viewing capability of the textfield although there is some odd behaviour.

    When I first click on the textfield: screen1

    When I click on the textfield for the second time, the popup moves to the top: screen2

    Is it possible to move the popup just a tad higher then original position and on the first textfield click?

    Thanks

    bug 
    opened by p0tvin29 6
  • Swift 5

    Swift 5

    Hello, I don't know if anyone is still maintaining this useful project. If there is, can you please help convert this project to the latest swift version.

    feature request 
    opened by GenCastro 5
  • Swift4

    Swift4

    Hello φ('ᴗ'」) I did support swfit4.

    Overview

    I did take a following task:

    • Update CDAlertView.swift file for Swift4 project.
    • Refactoring on keyboardWillShow, keyboardWillHide and popupMoved functions.
      • Used Early return.
    • Auto format using Swimat for CDAlertView.swift file.
    • Update docs for swift4.
    • Update .travis.yml file for Support Swift4.
    • Fix: Warnings.
    • Fix: Styles
    • Fix: Example project
    • Update project.pbxproj because:
      • Use Swift4
      • Fix this warning: The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference warnings, test your code with “Use of deprecated Swift 3 @objc inference” logging enabled, and disable Swift 3 @objc inference.**
        • See more: https://stackoverflow.com/questions/44379348/the-use-of-swift-3-objc-inference-in-swift-4-mode-is-deprecated
      • Used a Xcode9 recommended settings: this 2017-10-04 12 17 37 this 2017-10-04 12 20 34

    WIP Tasks

    None.

    Thank you.

    Refs https://github.com/candostdagdeviren/CDAlertView/issues/27

    opened by ykeisuke 5
  • Add ability to change spacing above and below message text

    Add ability to change spacing above and below message text

    I'd like to see an easy way to add spacing above and below the message text without having to add \n to my message string (that's a bit too much).

    Thanks!

    question feature request 
    opened by sgruby 5
  • Add ability to make textField becomeFirstResponder

    Add ability to make textField becomeFirstResponder

    This is an awesome library, thanks for doing it. It would be a cool enhancement if I could make the textField firstResponder so that the user could start typing immediately.

    enhancement good first issue 
    opened by mlchild 3
  • Handle action on tap

    Handle action on tap

    It isn't very clear in the documentation on how to handle different actions with a completion handler. Can someone please let me know how I can detect whether my "done action" or "cancel action" buttons are hit? Code is below. Thanks!

    `let alert = CDAlertView(title: "Deleting All Accounts", message: "Are you sure you wish to delete all accounts?", type: .warning)

    let doneAction = CDAlertViewAction(title: "Sure! 💪") alert.add(action: doneAction) let nevermindAction = CDAlertViewAction(title: "Nevermind 😬") alert.add(action: nevermindAction) alert.show()`

    opened by cdeck95 2
  • Many method are not available to used in Objective-C.

    Many method are not available to used in Objective-C.

    Hi,

    I try to use CDAlertView in a Obj-C project but I've noticed some methods are not available. For exemple hide(animations: CDAlertAnimationBlock? = nil, isPopupAnimated: Bool) is not here.

    I've install the library with CocoaPods.

    To try, I've created a new method in CDAlertView :

    public func hide(isPopupAnimated: Bool) { self.hide(animations: nil, isPopupAnimated: isPopupAnimated) }

    This one appear in the generated .h. It seem like the CDAlertAnimationBlock is the problem.

    opened by Ferannor 2
  • Keyboard Notification

    Keyboard Notification

    Hey guys, just wanted to see if this was a bug or my usage was incorrect - is the AlertView supposed to adjust its frame in the event of a keyboard show notification like a UIAlertController? As soon as the keyboard comes up (I have isTextFieldHidden set to false), it covers the bottom of the alert (+ button). Thanks!

    question 
    opened by asoong 2
  • Publish as Swift Package Manager package

    Publish as Swift Package Manager package

    Xcode now has a built-in package manager. Please support this so we can most easily use this package.

    I have documented entirely the process to publish a module at https://github.com/fulldecent/swift5-module-template

    opened by fulldecent 0
  • image icon doesn't work

    image icon doesn't work

    Hi, first of all thank you for your job, i think it's very nice. About my problem: i don't like use cocoapods so i have imported CdAlertView manually but when i call the alert view the image in the center doesn't work. this is a sample schermata 2018-05-22 alle 10 04 14

    opened by giuseppe69 0
Releases(0.11.0)
Owner
Candost Dagdeviren
Software Engineer | Blogger | Podcaster. Writes and talks about growing a career in software engineering and leadership.
Candost Dagdeviren
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
A simple and attractive AlertView to ask permission to your users for Push Notification.

A simple and attractive AlertView **to ask permission to your users for Push Notification.** PRESENTATION Ask permission to user for push notification

Boisney Philippe 37 Mar 23, 2022
FCAlertView is a Flat Customizable AlertView for iOS (Written in Objective C)

FCAlertView FCAlertView is a Flat Customizable AlertView, written in Objective C Quick Links 1. Swift 2. Installation 3. Example App 4. Adding FCAlert

Nima Tahami 794 Nov 29, 2022
The easiest way to display highly customizable in app notification banners in iOS

Written in Swift 5 NotificationBanner is an extremely customizable and lightweight library that makes the task of displaying in app notification banne

Dalton Hinterscher 4.5k Jan 9, 2023
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
FCAlertView is a Flat Customizable AlertView for iOS (Swift)

FCAlertView FCAlertView is a Flat Customizable AlertView, written in Swift [![CI Status](http://img.shields.io/travis/Nima Tahami/FCAlertView.svg?styl

Kris Penney 114 Apr 19, 2022
Highly configurable iOS Alert Views with custom content views

NYAlertViewController NYAlertViewController is a replacement for UIAlertController/UIAlertView with support for content views and UI customization. Fe

Nealon Young 609 Nov 20, 2022
AlertView A pop-up framework, Can be simple and convenient to join your project.

RAlertView AlertView A pop-up framework, Can be simple and convenient to join your project. Warning content Installation Depend on the project Masonry

杜耀辉 71 Aug 12, 2022
Cool AlertView

AMSmoothAlert • Now include multiple buttons feature you asked :) • Now available on Cocoapods : AMSmoothAlert I saw this pretty cool alert view conce

Antoine Marliac 1.3k Nov 20, 2022
A fully customizable popup style menu for iOS 😎

Guide Check out the documentation and guides for details on how to use. (Available languages:) English 简体中文 What's a better way to know what PopMenu o

Cali Castle 1.5k Dec 30, 2022
Customizable simple Alert and simple ActionSheet for Swift

SimpleAlert It is simple and easily customizable alert. Can be used as UIAlertController. Appetize's Demo Requirements Swift 5.0 iOS 9.0 or later How

Kyohei Ito 397 Dec 6, 2022
In-app notification in Swift, with customizable buttons and input text field.

Notie Undistracted in-app notification in Swift, with added buttons and input box. Installation CocoaPods To integrate Notie into your Xcode project u

Thi Doãn 85 Aug 8, 2020
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
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 Simple Customizable Alert With Swift

SimpleCustomizableAlert trying to make my very first library. Support Title Message (TextView) Image TextField Button Action Example let alert

null 1 Oct 26, 2021
OEANotification is a customizable notification view framework

OEANotification OEANotification is an iOS library which provides to create notifications and customize them easily. You can create notifications with

Ömer Aslan 19 Jan 30, 2021
Beautiful animated Alert View. Written in Swift

SCLAlertView Animated Alert View written in Swift, which can be used as a UIAlertView or UIAlertController replacement. Since UIAlertView is deprecate

Viktor Radchenko 5.2k Jan 3, 2023
Live animated Alert View for iOS written in Swift

Sweet Alert iOS Beautiful Animated custom Alert View inspired from javascript library SweetAlert. Written in Swift this SweetAlertView can be used in

Sahil 2k Dec 22, 2022
Beautiful animated Login Alert View. Written in Objective-C

UIAlertView - Objective-C Animated Login Alert View written in Swift but ported to Objective-C, which can be used as a UIAlertView or UIAlertControlle

Letovsky 2 Dec 22, 2021