Git Product home page Git Product logo

daalertcontroller's Introduction

DAAlertController

[![CI Status](http://img.shields.io/travis/Daria Kopaliani/DAAlertController.svg?style=flat)](https://travis-ci.org/Daria Kopaliani/DAAlertController) Version License Platform

If you are a luckier developer and only target iOS 8+ devices, enjoy the new UIAlertController, otherwise check DAAlertController out, it’s a real timesaver.
DAAlertController provides a convenient block-based interface for configuration and presentation of UIAlertViews and UIActionSheets. If UIAlertContoller is available DAAlertController will just pass all the work to it, otherwise it will use associated references (explained in detail later) to invoke action handlers when buttons are clicked just like UIAlertController would.

Naturally, DAAlertController is limited to what the old UIAlertView and UIActionSheet could do:

  • action sheets can only have one destructive button (buttons for other destructive actions will be rendered as default buttons)
  • alert views cannot have any destructive buttons (again, all buttons will look like default buttons)
  • alert views can only have up to 2 text fields
  • action sheets can only have a title; a message will not be displayed
  • you can only specify up to 10 actions for iOS 7 (otherwise alert views / action sheets would not be rendered properly anyways)

Usage

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

Let’s take a look at the case of a simple alert view:

DAAlertAction *cancelAction = [DAAlertAction actionWithTitle:@"Cancel"
                                                       style:DAAlertActionStyleCancel handler:nil];
DAAlertAction *signOutAction = [DAAlertAction actionWithTitle:@"Sign out"
                                                        style:DAAlertActionStyleDestructive handler:^{
                                                            // perform sign out
                                                        }];
[DAAlertController showAlertViewInViewController:self
                                       withTitle:@"Are you sure you want to sign out?"
                                         message:@"If you sign out of your account all photos will be removed from this iphone."
                                         actions:@[cancelAction, signOutAction]];

Here is what you will get for iOS 8 and 7: (UIAlertView does not support destructive buttons so "Sign out" button will be rendered as a default button)

iOS 8+ iOS 7

Presenting an alert view with 2 textfields ("sign up" button should only be enabled when "nickname" is at least 5 letters long) would look like

DAAlertAction *cancelAction = [DAAlertAction actionWithTitle:@"Cancel" style:DAAlertActionStyleCancel handler:nil];
DAAlertAction *signUpAction = [DAAlertAction actionWithTitle:@"Sign up" style:DAAlertActionStyleDefault handler:^{
    // perform sign up
}];
[DAAlertController showAlertViewInViewController:self
                                       withTitle:@"Sign up"
                                         message:@"Please choose a nick name."
                                         actions:@[cancelAction, signUpAction]
                              numberOfTextFields:2
                  textFieldsConfigurationHandler:^(NSArray *textFields)
{
    UITextField *nickNameTextField = [textFields firstObject];
    nickNameTextField.placeholder = @"Nick name";
    UITextField *fullNameTextField = [textFields lastObject];
    fullNameTextField.placeholder = @"Full name";
} validationBlock:^BOOL(NSArray *textFields) {
    UITextField *nickNameTextField = [textFields firstObject];
    return nickNameTextField.text.length >= 5;
}];
iOS 8+ iOS 7

Methods for presenting action sheets are quite similar, but they also include parameters for sourceView or barButttonItem and permittedArrowDirections.

iOS 8+ iOS 7

Installation

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

pod "DAAlertController"

License

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

daalertcontroller's People

Contributors

daria-kopaliani avatar fritzgerald avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.