Highly configurable iOS Alert Views with custom content views

Overview

NYAlertViewController

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

Example

Features

  • Includes content view property for adding custom views to the alert view
  • Block-based API similar to UIAlertController/UIAlertAction
  • Support for all screen orientations and iPad screen sizes
  • Easily add text fields with simple API identical to UIAlertController
  • Choose between fade (similar to UIAlertController) or slide transition animations

Installation

Manual

Add the files to your project manually by dragging the NYAlertViewController directory into your Xcode project.

CocoaPods

Add pod 'NYAlertViewController' to your Podfile, and run pod install.

Usage Example

An Objective-C example project demonstrating customization options is included in the NYAlertViewControllerDemo directory.

Objective-C

// Import the class and create an NYAlertViewController instance
#import "NYAlertViewController.h"

// ...

// Set a title and message
NSString *title = @"Location Permission";
NSString *message = @"Set the alertViewContentView property to add custom views to the alert view";

// Customize appearance as desired
NYAlertViewControllerConfiguration *configuration = [NYAlertViewControllerConfiguration new];
configuration.contentViewInset = UIEdgeInsetsMake(12.0f, 8.0f, 8.0f, 8.0f);
configuration.alertViewBackgroundColor = [UIColor colorWithRed:0.23f green:0.23f blue:0.27f alpha:1.0f];
configuration.separatorColor = [UIColor colorWithRed:0.16f green:0.16f blue:0.2f alpha:1.0f];
configuration.titleTextColor = [UIColor whiteColor];
configuration.messageTextColor = [UIColor whiteColor];

configuration.buttonConfiguration = [NYAlertActionConfiguration new];
configuration.buttonConfiguration.titleColor = [UIColor whiteColor];

configuration.cancelButtonConfiguration.titleColor = [UIColor whiteColor];

// Set up alert actions
NYAlertAction *cancelAction = [[NYAlertAction alloc] initWithTitle:@"Later"
                                                             style:UIAlertActionStyleCancel
                                                           handler:nil];
NYAlertAction *okAction = [[NYAlertAction alloc] initWithTitle:@"Ok"
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(NYAlertAction *action) {
                                                           [self doSomething];
                                                       }]];

NYAlertViewController *alertViewController = [[NYAlertViewController alloc] initWithOptions:configuration
                                                                                      title:title
                                                                                    message:message
                                                                                    actions:@[cancelAction, okAction]];

// Optionally add a content view
UIImageView *iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MapIcon"]];
iconImageView.contentMode = UIViewContentModeScaleAspectFit;
[iconImageView.heightAnchor constraintEqualToConstant:60.0f].active = YES;
alertViewController.alertViewContentView = iconImageView;

// Present the alert view controller
[self presentViewController:alertViewController animated:YES completion:nil];

License

This project is released under the MIT License.

Comments
  • Podspec issue?

    Podspec issue?

    [!] Unable to satisfy the following requirements:

    • NYAlertViewController required by Podfile
    • NYAlertViewController required by Podfile
    • NYAlertViewController required by Podfile
    opened by nishal 2
  • IOS7  cause AutoLayout issue!

    IOS7 cause AutoLayout issue!

    ultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSLayoutConstraint:0x14d9eeb0 V:|-(NSSpace(20))-[UILabel:0x14e71890] (Names: '|':UIView:0x14e717b0 )>", "<NSLayoutConstraint:0x14d69fc0 V:[UILabel:0x14e71890]-(2)-[NYAlertTextView:0x15b68200]>", "<NSLayoutConstraint:0x14d3e400 V:[NYAlertTextView:0x15b68200]-(0)-[UIView:0x14e7d1a0]>", "<NSLayoutConstraint:0x14d78910 V:[UIView:0x14e7d1a0]-(0)-[UIView:0x14e71560]>", "<NSLayoutConstraint:0x14db66b0 V:[UIView:0x14e71560]-(0)-[UIView:0x14e6fb90]>", "<NSLayoutConstraint:0x14d72630 V:[UIView:0x14e6fb90]-(NSSpace(20))-| (Names: '|':UIView:0x14e717b0 )>", "<NSLayoutConstraint:0x14e6fac0 UIView:0x14e717b0.height <= 0.9*NYAlertView:0x14e714a0.height>", "<NSAutoresizingMaskLayoutConstraint:0x14dccaa0 h=--& v=--& V:[NYAlertView:0x14e714a0(0)]>" )

    opened by Marlonzl 1
  • Added method to return bg view

    Added method to return bg view

    Hey

    I added a method to get the background view of the alert itself. This makes it possible to modify things such as dropped shadow, border properties etc. of the alert.

    I use this myself and figured I might as well update the repo.

    opened by nickdnk 0
  • Please add carthage support

    Please add carthage support

    Dependency "NYAlertViewController" has no shared framework schemes for any of the platforms: iOS
    
    If you believe this to be an error, please file an issue with the maintainers at https://github.com/nealyoung/NYAlertViewController/issues/new
    
    opened by larryonoff 0
  • Pod version 2.0.0 is not available

    Pod version 2.0.0 is not available

    I tried updating to version 2.0.0 but Pod version is not available. Can you please let me know if its still not released to Cocoapods.

    And how can I use this library

    Thanks

    opened by vikasAccion 1
Releases(2.0.0)
Owner
Nealon Young
Nealon Young
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
Custom alert View to iOS applications

A simple, easy and custom iOS UIAlertView written in Swift Malert came to facilitates custom alert views as UIAlertController. Malert allows you to pe

Vitor Mesquita 480 Oct 29, 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
(Experimental libraries) Controls interrupt handling, such as alert views, and is compatible with UIKit and Swift UI.

UIPresentCoordinator Controls interrupt handling, such as alert views, and is compatible with UIKit and Swift UI. This library manages items that are

Yuki Tamazawa 1 Jan 22, 2022
A colored alert view for your iOS.

日本語 KRAlertController KRAlertController is a beautiful and easy-to-use alert controller for your iOS written by Swift. Requirements iOS 10.0+ Xcode 10

K.R.Impedance 52 Jun 30, 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
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
A Swift package for iOS/tvOS for easy alert presentation

AlertPresenter Listed on the Swift Package Index and originally posted on my blog. It can be fiddly to handle the presentation of alerts on a specific

Chris Mash 14 Jul 1, 2022
Simple DropDown Alert View For Any iOS Projects.

⚠️ DEPRECATED, NO LONGER MAINTAINED JDropDownAlert JDropDownALert Simple DropDown Alert View For Any iOS Projects. Usage Top let alert = JDropDown

WonJo 71 Jul 17, 2022
TextFieldAlert - A SwiftUI alert with text field(s) for iOS 13 and greater.

TextFieldAlert A SwiftUI alert with text field(s) for iOS 13 and greater. As Apple is going to introduce text field(s) as an alert actions in iOS 16,

Piotr Sochalewski 13 Dec 5, 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
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
Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets.

SPAlert Popup from Apple Music & Feedback in AppStore. Contains Done, Heart, Error and other presets. Supports Dark Mode. I tried to recreate Apple's

Ivan Vorobei 1.8k Jan 7, 2023
Zingle – An alert will display underneath your UINavigationBar 🎅

Zingle Zingle – An alert will display underneath your UINavigationBar ?? ?? Note: Zingle has a dependency to have a UINavigationController in your app

Hemang 109 Jun 24, 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
Animated alert library like Swarm app.

TKSwarmAlert Animation Tool for Alert like Swarm app. ScreenShot Installation CocoaPods You can use CocoaPods to install TKSwarmAlert by adding it to

Takuya Okamoto 581 Dec 2, 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
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