Git Product home page Git Product logo

stalertview's Introduction

STAlertView

Version License Platform

The idea of this component is to improve the readability while using the native UIAlertView. The UIKit alert view works with delegates. When you have two or more alerts at the same controller, it becomes a problem because you have to use the TAG to identify from which UIAlertView comes the user.

With STAlertView you will be able to define the behavior of the 'Ok' and 'Cancel' button, at the same place where you declare the alert view. So, let's see some code:

[[[STAlertView alloc] initWithTitle:@"Title" 
        message:@"Message"
        cancelButtonTitle:@"Cancel"
        otherButtonTitle:@"Ok"
        cancelButtonBlock:^{
            NSLog(@"do something at cancel");
            
        } otherButtonBlock:^{
            NSLog(@"do something at ok");
            
        }] show];

And that's it, no pieces of code everywhere, just a few lines and all the related code together. As it is a native UIAlertView, the result of using STAlertView is like the native one:

Screenshot

This component has been made thanks to the answer of Ricky Helgesson at StackOverflow.

Demo usage

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

Requirements

Is compatible with ARC and non-ARC.

Installation

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

pod "STAlertView"

Then at the view controller that you want to show the alert view add at the .h:

#import <STAlertView/STAlertView.h>
...
@property (nonatomic, strong) STAlertView *alertView;
...
@end

And at the .m:

...
self.alertView = [[STAlertView alloc] initWithTitle:@"Title of the alert" 
        message:@"Message you want to show"
        cancelButtonTitle:@"No" 
         otherButtonTitle:@"Yes"
        cancelButtonBlock:^{
            // Code todo when the user cancel
            ...
        } otherButtonBlock:^{
            // Code todo when the user accept
            ...
        }];
[self.alertView show]
...

You can make any customization to the UIAlertView, using the reference of the alertview. For example:

    self.stAlertView = [[STAlertView alloc] initWithTitle:@"Alert view with a textfield"
        message:@"Native UIAlertView with a textfiled."
        textFieldHint:@"Write something"
        textFieldValue:nil
        cancelButtonTitle:@"Cancel"
        otherButtonTitle:@"Store"

        cancelButtonBlock:^{
            ...
        } otherButtonBlock:^(NSString * result){
            ...
        }];

    //You can make any customization to the native UIAlertView
    self.stAlertView.alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    [[self.stAlertView.alertView textFieldAtIndex:1] setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];

    [self.stAlertView show];

Author

Nestor Malet - @NestorMalet

License

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

Donating

Support this project via gittip.

Support via Gratipay

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.