Latest | 0.1.0 |
---|---|
Homepage | https://github.com/gunpowderlabs/GUNAlert |
License | MIT |
Platforms | ios 7.0, requires ARC |
Frameworks | UIKit |
Authors |
GUNAlert is a simple wrapper around UIAlertView and UIAlertController. For applications that need to keep backward compatibility with iOS versions < 8.
It is designed as a simple drop in solution for most common use cases.
Usage
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Setup
Before using alerts you will need to instantiate GUNAlert
class and make sure it’s reference will not disappear until the alert is handled.
Here’s an example:
In your UIViewController
create an instance of GUNAlert
class and assign it as a strong
property.
@interface MyViewController ()
@property (strong, nonatomic) GUNAlert *alert;
@end
@implementation GUNViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.alert = [[GUNAlert alloc] initWithViewController: self];
}
@end
In most cases you will want to inform user about a fact and acknowledge it or make a decision. To facilitate this GUNAlert
provides two helper methods:
Showing a ‘Cancel’ alert
To instantiate ‘Cancel’ alert or in other words alert with one action use the following method:
[self.alert cancelAlertWithTitle:@"Success!"
message:@"You've just won a lottery."
cancelTitle:@"Yay!"
cancelHandler:^{
[self transferLargeSumOfMoney];
}];
Showing a ‘Cancel & Ok’ alert
To instantiate ‘Cancel & Ok’ alert or in other words alert with two actions use the following method:
[self.alert cancelOkAlertWithTitle:@"Your meal is ready!"
message:@"Do you want something to drink?"
cancelTitle:@"Not really"
cancelHandler:^{
[self prepareOrder];
}
okTitle:@"Sure I do"
okHandler:^{
[self addDrinkToOrder];
[self prepareOrder];
}];
Showing an alert with more than 2 actions
First prepare an array with titles for each action.
NSArray *titles = @[
@"Yes",
@"No",
@"Maybe"
];
Then prepare an array of handlers for each action. Both arrays must have the same number of elements.
NSArray *handlers = @[
^{
[self makeACall]
},
^{
},
^{
if (arc4random_uniform(2)) {
[self makeACall]
};
},
];
Finally use both arrays in the following method:
[self.alert alertWithTitle:@"Hey I've just met you"
message:@"Call me"
titles:titles
handlers:handlers];
Requirements
Tested in iOS 7.1 and iOS 8
Installation
With CocoaPods
GUNAlert is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod "GUNAlert"
By Hand
Copy GUNAlert.h and GUNAlert.m to your project and modify according to your preference.
Author
Michał Taszycki, [email protected]
License
GUNAlert is available under the MIT license. See the LICENSE file for more info.
Latest podspec
{ "name": "GUNAlert", "version": "0.1.0", "summary": "GUNAlert is a simple wrapper around UIAlertView and UIAlertController", "description": " For applications that need to keep backward compatibility with iOS versions < 8. It is designed as a simple drop in solution for most common use cases.n", "homepage": "https://github.com/gunpowderlabs/GUNAlert", "license": "MIT", "authors": { "Michau0142 Taszycki": "[email protected]" }, "source": { "git": "https://github.com/gunpowderlabs/GUNAlert.git", "tag": "0.1.0" }, "social_media_url": "https://twitter.com/mehowte", "platforms": { "ios": "7.0" }, "requires_arc": true, "source_files": "Pod/Classes", "resource_bundles": { "GUNAlert": [ "Pod/Assets/*.png" ] }, "public_header_files": "Pod/Classes/*.h", "frameworks": "UIKit" }
Sun, 06 Mar 2016 20:08:04 +0000