Latest 1.0.0
Homepage https://github.com/nmaletm/STAlertView
License MIT
Platforms ios 6.0, requires ARC
Frameworks UIKit
Authors

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

Latest podspec

{
    "name": "STAlertView",
    "version": "1.0.0",
    "summary": "Wrapper of the native UIAlertView that work with blocks",
    "description": "    Do you like to use the UIAlertViewDelegate for each UIAlertView? Specially when there are more than one at the same view controller. With STAlertView, you will be able to define the behavior of Yes/No with a block, at the same place you n    create the alert view. This will increase the readability of your code.n",
    "homepage": "https://github.com/nmaletm/STAlertView",
    "screenshots": [
        "https://raw.githubusercontent.com/nmaletm/STAlertView/master/Screenshots/screenshot.png",
        "https://raw.githubusercontent.com/nmaletm/STAlertView/master/Screenshots/screenshot2.png"
    ],
    "license": "MIT",
    "authors": {
        "Nestor Malet": "[email protected]"
    },
    "source": {
        "git": "https://github.com/nmaletm/STAlertView.git",
        "tag": "1.0.0"
    },
    "social_media_url": "https://twitter.com/NestorMalet",
    "platforms": {
        "ios": "6.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes",
    "resource_bundles": {
        "STAlertView": [
            "Pod/Assets/*.png"
        ]
    },
    "public_header_files": "Pod/Classes/**/*.h",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This