A highly customizable alert dialog controller that mimics Snapchat's alert dialog.

Overview

AZDialogViewController

A highly customizable alert dialog controller that mimics Snapchat's alert dialog.

CocoaPods CocoaPods CocoaPods

Screenshots


Installation

CocoaPods:

pod 'AZDialogView'

Carthage:

github "Minitour/AZDialogViewController"

Manual:

Simply drag and drop the Sources folder to your project.

Usage

Create an instance of AZDialogViewController:

//init with optional parameters
let dialog = AZDialogViewController(title: "Antonio Zaitoun", message: "minitour")

Customize:

//set the title color
dialog.titleColor = .black

//set the message color
dialog.messageColor = .black

//set the dialog background color
dialog.alertBackgroundColor = .white

//set the gesture dismiss direction
dialog.dismissDirection = .bottom

//allow dismiss by touching the background
dialog.dismissWithOutsideTouch = true

//show seperator under the title
dialog.showSeparator = false

//set the seperator color
dialog.separatorColor = UIColor.blue

//enable/disable drag
dialog.allowDragGesture = false

//enable rubber (bounce) effect
dialog.rubberEnabled = true

//set dialog image
dialog.image = UIImage(named: "icon")

//enable/disable backgroud blur
dialog.blurBackground = true

//set the background blur style
dialog.blurEffectStyle = .dark

//set the dialog offset (from center)
dialog.contentOffset = self.view.frame.height / 2.0 - dialog.estimatedHeight / 2.0 - 16.0

Add Actions:

dialog.addAction(AZDialogAction(title: "Edit Name") { (dialog) -> (Void) in
        //add your actions here.
        dialog.dismiss()
})
        
dialog.addAction(AZDialogAction(title: "Remove Friend") { (dialog) -> (Void) in
        //add your actions here.
        dialog.dismiss()
})
        
dialog.addAction(AZDialogAction(title: "Block") { (dialog) -> (Void) in
        //add your actions here.
        dialog.dismiss()
})

Add Image:

dialog.imageHandler = { (imageView) in
       imageView.image = UIImage(named: "your_image_here")
       imageView.contentMode = .scaleAspectFill
       return true //must return true, otherwise image won't show.
}

Custom View

/*
 customViewSizeRatio is the precentage of the height in respect to the width of the view. 
 i.e. if the width is 100 and we set customViewSizeRatio to be 0.2 then the height will be 20. 
 The default value is 0.0.
*/
dialog.customViewSizeRatio = 0.2

//Add the subviews
let container = dialog.container
let indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
dialog.container.addSubview(indicator)

//add constraints
indicator.translatesAutoresizingMaskIntoConstraints = false
indicator.centerXAnchor.constraint(equalTo: container.centerXAnchor).isActive = true
indicator.centerYAnchor.constraint(equalTo: container.centerYAnchor).isActive = true
indicator.startAnimating()

Present The dialog:

dialog.show(in: self)

//or

//Make sure to have animated set to false otherwise you'll see a delay.
self.present(dialog, animated: false, completion: nil)

Show with completion

dialog.show(in: self) { dialog in
    // show and then change the offset
    dialog.contentOffset = self.view.frame.height / 2.0 - dialog.estimatedHeight / 2.0 + 15
}

Design

Change Dialog Width

This has been a requested feature and so I decided to add it. You can change the width of the dialog frame as a ratio in respect to the width of the main view. This can only be doing using the initalizer and the width cannot be modified afterwards.

let dialog = AZDialogViewController(title: "Switch Account", message: "My Message", widthRatio: 1.0)

This will display a dialog which has the same width as the the controller it is presented in.

The default value is 0.75

Customize Action Buttons Style:

dialog.buttonStyle = { (button,height,position) in
     button.setBackgroundImage(UIImage.imageWithColor(self.primaryColorDark), for: .highlighted)
     button.setTitleColor(UIColor.white, for: .highlighted)
     button.setTitleColor(self.primaryColor, for: .normal)
     button.layer.masksToBounds = true
     button.layer.borderColor = self.primaryColor.cgColor
}

Use custom UIButton sub-class:

dialog.buttonInit = { index in
    //set a custom button only for the first index
    return index == 0 ? HighlightableButton() : nil
}

Customize Tool Buttons:

dialog.rightToolStyle = { (button) in
        button.setImage(UIImage(named: "ic_share"), for: [])
        button.tintColor = .lightGray
        return true
}      
dialog.rightToolAction = { (button) in
        print("Share function")
}

dialog.leftToolStyle = { (button) in
        button.setImage(UIImage(named: "ic_share"), for: [])
        button.tintColor = .lightGray
        return true
}      
dialog.leftToolAction = { (button) in
        print("Share function")
}

Customize Cancel Button Style:

dialog.cancelEnabled = true

dialog.cancelButtonStyle = { (button,height) in
        button.tintColor = self.primaryColor
        button.setTitle("CANCEL", for: [])
        return true //must return true, otherwise cancel button won't show.
}
Comments
  • Change font size?

    Change font size?

    When I present the alert view the fonts are both pretty small. I tried: dialog.titleFontSize = CGFloat(30.0) however it gives me an error saying that titleFontSize setter is inaccessible.

    opened by mattpidd 14
  • No custom view support

    No custom view support

    Hi,

    It seems there is no support for adding a custom view...

    I tried to add a custom view within the code but it does not show anything.

    Regards, Andre

    opened by andresteves 5
  • iPhone XS Max support?

    iPhone XS Max support?

    I everyone, I've been testing AZDialogView with iPhone XS Max screen sizes, and the view controller is rendered oddly. It appears very small on the ViewController

    opened by carrarodev 4
  • Re-Call Bug

    Re-Call Bug

    Hi Again;

    I found another mistake while using it. If you make closure type initializing and many times dialog.show(in: self) method calling you then after the dismiss operation is goes a bug.

    my code is here ----

    http://notes.io/m4ik

    opened by zezeron 4
  • Flattened button sizes for iPhone X screen size.

    Flattened button sizes for iPhone X screen size.

    The UIButtons in the AZDialogViewController have buttons that are flattened and are not proportional to what the buttons should look like according to the readme for iPhone X screen sizes. Are you using the Safe Area layout guide?

    opened by HackShitUp 4
  • Is there a way to know when dismiss() on the dialog is called?

    Is there a way to know when dismiss() on the dialog is called?

    When I show my dialog to the user, he/she has two options:

    1. Tap on "Yes"
    2. Tap on "Cancel" or just tap on the screen or move the dialog upwards or downwards.

    Is there a way to absolutely cover the 2 option in one method, thereforing listening to the dismissal call?

    Cancel and tap on screen (touchesBegan:) wouldn't be a problem to recognize, while upwards/downwards swipe/pan would be.

    opened by ramonsgds 3
  • Unable to customize UIButton.

    Unable to customize UIButton.

    I've been trying to modify the AZDialogView's buttons to make them look like the default iOS alert controllers (with a button image in it), but with the gesture-dismissing capabilities of this project. But, I can't customize the button for some reason. Here's my code:

    // Configure UIButton styles
            dialogController.buttonStyle = { (button, height, position) in
                // Fill button with color
                button.setImage(UIImage(named: "pop"), for: .normal)
                button.semanticContentAttribute = .forceLeftToRight
                button.titleLabel?.font = UIFont(name: "AvenirNext-Demibold", size: 16)
                button.layer.masksToBounds = true
            }
    
    opened by HackShitUp 3
  • Using dynamic data with AZDialogViewController

    Using dynamic data with AZDialogViewController

    Thank you for this wonderful library. Can you please point me to how to be able to do some thing like this.

    let data = ["A", "B", "C"]
    
    for i in 0 ..< data.count {            
          dialog.addAction(AZDialogAction(title: data[i], handler: doSomething(title or index)))
    }
    
    func doSomething(index: Int or title: String){
    
    if title == "A" or index == 0 {
            //do something
      }
    }
    
    opened by moderateepheezy 3
  • Support iPad Landscape

    Support iPad Landscape

    Hello,

    I just removed the FixedNavigationController in my Projekt, but the Dialogs are too wide and big on iPads in Landscape. Portrait is okay on both devices.

    thanks

    opened by dungi 3
  • Issue when Dismissing

    Issue when Dismissing

    Dismissing Alert is also dismiss other alert which is shown after dismiss... is it because of super.dismiss when dismissing ??

    Please some one let me know solution ...

    opened by kishanios123 2
  • Override height for calculations?

    Override height for calculations?

    I am using AZDialog in my project, but when I try to display a dialog in a custom modal view, the dialog is squeezed. I think this is happening because the custom modal is smaller than the screen height (music app style) - If I present this view with a normal modal presentation style, the dialog works fine. Is there any way to override the height function of the dialog without altering the core dialog view code?

    354D087F-358A-4919-86D8-932CF785734A 2B13C3BA-76BB-4291-867B-A722F2FE3A4D

    bug 
    opened by RNUK 2
  • set leftToolItem.heightAnchor.constraint in accordance to rightToolItem.heightAnchor.constraint

    set leftToolItem.heightAnchor.constraint in accordance to rightToolItem.heightAnchor.constraint

    Hi, In setupToolItems(), would you consider to set leftToolItem.heightAnchor.constraint in as the same as rightToolItem.heightAnchor.constraint? Original: if leftToolStyle?(leftToolItem) ?? false{ baseView.addSubview(leftToolItem) leftToolItem.topAnchor.constraint(equalTo: baseView.topAnchor, constant: spacing2).isActive = true leftToolItem.leftAnchor.constraint(equalTo: baseView.leftAnchor,constant: spacing2).isActive = true leftToolItem.widthAnchor.constraint(equalTo: leftToolItem.heightAnchor).isActive = true leftToolItem.addTarget(self, action: #selector(AZDialogViewController.handleLeftTool(:)), for: .touchUpInside) } How about? if leftToolStyle?(leftToolItem) ?? false{ baseView.addSubview(leftToolItem) leftToolItem.topAnchor.constraint(equalTo: baseView.topAnchor, constant: spacing2).isActive = true leftToolItem.leftAnchor.constraint(equalTo: baseView.leftAnchor,constant: spacing2).isActive = true leftToolItem.widthAnchor.constraint(equalTo: leftToolItem.heightAnchor).isActive = true leftToolItem.heightAnchor.constraint(equalToConstant: 20).isActive = true leftToolItem.addTarget(self, action: #selector(AZDialogViewController.handleLeftTool(:)), for: .touchUpInside) }

    Thank you very much for the sharing!

    Regards, godustin

    opened by godustin 0
Releases(1.3.4)
  • 1.3.4(Mar 16, 2019)

    • Added applyAnimatedTranslation function which allows you to apply simulated dragging. This can be used when simulating a scroll.
    • Exposed the UIPanGestureRecognizer object of the main frame allow delegation control externally.
    Source code(tar.gz)
    Source code(zip)
  • 1.3.1(Mar 13, 2019)

    • Grouped all constants into a configurable struct.
    • Added better support iPhones and iPads.
    • Fixed bug where if dialog is presented in a navigation controller the fonts appear small.
    Source code(tar.gz)
    Source code(zip)
  • 1.2.1(Dec 13, 2017)

    Added New APIs

    • Added blurBackground - true by default, shows a UIVisualEffectView when displaying the dialog.
    • Added blurEffectStyle - default is .dark
    • Added buttonInit closure variable which allows the initalization of a custom UIButton.

    Usage Examples:

    
    //true by default
    dialog.blurBackground = true
    
    //default is dark
    dialog.blurEffectStyle = .extraLight
    
    dialog.buttonInit = { index in
        //set a custom button only for the first index
        return index == 0 ? HighlightableButton() : nil
    }
    
    Source code(tar.gz)
    Source code(zip)
  • 1.1.4(Aug 4, 2017)

    • Fixed content offset bug.
    • Added estimatedHeight var that returns the estimated height of the dialog view even it if it hasn't been loaded yet.
    • Added rubberEnabled var which is true by default. when enabled it will add a rubber effect when trying to swipe the dialog up.
    Source code(tar.gz)
    Source code(zip)
  • 1.1.3(Jul 25, 2017)

Owner
Antonio Zaitoun
23, Mobile Dev & System architect. Software Engineer at GE Healthcare. Information Systems B.Sc. Graduate and M.Sc. student at University of Haifa.
Antonio Zaitoun
Simple selection dialog

SelectionDialog Simple selection dialog inspired from ios-custom-alertview Preview Requirements iOS 8.0+ Swift 3 Xcode 8.0 Installation CocoaPods use_

Lee Sun-Hyoup 117 Aug 5, 2022
Show MS Windows style activation dialog on my screen.

Activate Mac The "Activate Windows" watermark ported to macOS with Swift Objective-C. Special thanks: MrGlockenspiel/activate-linux for the idea. Inst

Lakr Aream 195 Dec 23, 2022
SSToastMessage is written purely in SwiftUI. It will add toast, alert, and floating message view over the top of any view. It is intended to be simple, lightweight, and easy to use. It will be a popup with a single line of code.

SSToastMessage SSToastMessage is written in SwiftUI. It will add toast, alert, and floating message view over the top of any view. It is intended to b

Simform Solutions 223 Dec 2, 2022
Pop-up based view(e.g. alert sheet), can be easily customized.

MMPopupView 中文介绍 A basic Pop-Up Kit allows you to easily create Pop-Up view. You can focus on the only view you want to show. Besides, it comes with 2

ralph li 2.1k Jan 3, 2023
PopupController is a controller for showing temporary popup view.

PopupController PopupController is a controller for showing temporary popup view. Demo Try PopupController on Appetize.io Installation CocoaPods pod '

daisuke sato 338 Dec 14, 2022
Subscription View Controller like the Tinder uses

SubscriptionPrompt SubscriptionPrompt is a UIViewController with a carousel at the top and a number of rows at the bottom. Written in Swift, works for

Binur Konarbai 235 Nov 17, 2022
Create fully customizable popups easier than ever before ⚜️

FlexFlex Create fully customizable popups easier than ever before. ?? Installation FlexFlex requires iOS 13 and Xcode 12. 1️⃣ In Xcode go to File ➤ Ad

adri567 2 Aug 15, 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
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
Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift

CDAlertView is highly customizable alert popup written in Swift. Usage is similar to UIAlertController. Screenshots Animations Usage Basic usage witho

Candost Dagdeviren 1.1k Dec 30, 2022
Highly customizable Action Sheet Controller with Assets Preview written in Swift

PPAssetsActionController Play with me ▶️ ?? If you want to play with me, just tap here and enjoy! ?? ?? Show me ?? Try me ?? The easiest way to try me

Pavel Pantus 72 Feb 4, 2022
A paging view controller with a highly customizable menu ✨

Getting Started | Customization | Installation Features Parchment lets you page between view controllers while showing any type of generic indicator t

Martin Rechsteiner 3k Jan 8, 2023
Highly customizable Action Sheet Controller with Assets Preview written in Swift

PPAssetsActionController Play with me ▶️ ?? If you want to play with me, just tap here and enjoy! ?? ?? Show me ?? Try me ?? The easiest way to try me

Pavel Pantus 72 Feb 4, 2022
FacebookMe is a Swift App Mimics the personal profile tab of Facebook.

FacebookMe FacebookMe is a Swift App Mimics the personal profile tab of Facebook. It demos one simple way to implement a UITableView with mutiple sect

Kushal Shingote 3 Feb 20, 2022
DGCropImage - A photo cropping tool which mimics Photo.app written by Swift

DGCropImage A photo cropping tool which mimics Photo.app written by Swift. This

donggyu 11 Jul 14, 2022
Allows you to use custom maps in iphone applications and attempts to mimics some of the behaviour of the MapKit framework

NAMapKit Lets you drop pins or custom annotations onto a standard UIImage or a tiled NATiledImageView. Includes callouts, multi-colored pins, animatio

Neil Ang 263 Jun 29, 2022
A Metal application that mimics SAO "Link Start" scene.

SAO Link Start Effect This is a Metal application that mimics SAO "Link Start" scene. Building The project requires Xcode 13.3 or later version. The a

Cyandev 28 Aug 3, 2022
UIEnvironment - A framework that mimics the SwiftUI view's environment to replicate the value distribution thought your UIKit app.

A framework that mimics the SwiftUI view's environment to replicate the value distribution thought your UIKit view hierarchy. Overview D

Łukasz Śliwiński 15 Dec 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
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