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

stalertview's People

Contributors

nmaletm avatar

Stargazers

 avatar zhang avatar RuweiLi avatar Leeway avatar  avatar  avatar dito avatar  avatar 坠飘尘 avatar viwii avatar Michael.Yang avatar chx.li avatar Abner avatar  Dream avatar yangji avatar hemingwayEGS avatar snapking avatar  avatar LΞO avatar Raymond avatar  avatar  avatar cabbgeHL avatar  avatar  avatar Evan Xu avatar airbob avatar  avatar Denis Bogatyrev avatar Ali Can Batur avatar stevenlfg avatar Tubie avatar Fly Corleone avatar shiqiang avatar thuantm avatar Wang Shuai avatar  avatar jianpx avatar 破船 avatar  avatar 葛文明 avatar  avatar  avatar Jornathan Thorne avatar Zach Graham avatar Kevin.Xiao avatar  avatar  avatar  avatar Kostas Antonopoulos avatar TP avatar Xiao Yulong avatar  avatar Herbert Siojo avatar Lukasz Piliszczuk avatar Jason Holt avatar fahrulazmi avatar  avatar Weihan avatar Pierre Rougeot avatar Carabineiro avatar  avatar Dmytro Vlasenko avatar

Watchers

arden avatar  avatar James Cloos avatar chenxi avatar Carabineiro avatar Sergii Koval avatar Michael.Yang avatar  avatar

stalertview's Issues

Buttons / UITextField

I was looking for a replacement for the uialertview with three buttons, ok, forgot and cancel, be nice to see a screenshot with more buttons and a uitextfield, maybe example code showing how to access the text value too.

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.