Skip to content

Commit

Permalink
Brand new API, Introducing compatibility with iOS8+ UIAlertController…
Browse files Browse the repository at this point in the history
… (it was about time!)
  • Loading branch information
AliSoftware committed Jul 29, 2015
1 parent b41e998 commit bc38906
Show file tree
Hide file tree
Showing 10 changed files with 443 additions and 878 deletions.
13 changes: 13 additions & 0 deletions Example/AlertsViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// AlertsViewController.h
// OHAlertsExample
//
// Created by Olivier Halligon on 29/07/2015.
//
//

#import <UIKit/UIKit.h>

@interface AlertsViewController : UIViewController

@end
97 changes: 97 additions & 0 deletions Example/AlertsViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//
// AlertsViewController.m
// OHAlertsExample
//
// Created by Olivier Halligon on 29/07/2015.
//
//

#import "AlertsViewController.h"
#import "OHAlertView.h"

@interface AlertsViewController ()
@property (nonatomic, retain) IBOutlet UILabel *status;
@end

@implementation AlertsViewController


-(IBAction)showAlert1
{
[OHAlertView showAlertWithTitle:@"Alert Demo"
message:@"Welcome to this sample"
cancelButton:nil
otherButtons:@[@"Thanks!"]
buttonHandler:^(OHAlertView* alert, NSInteger buttonIndex)
{
self.status.text = @"Welcome !";
}];
}

/////////////////////////////////////////////////////////////////////////////


-(IBAction)showAlert2
{
[OHAlertView showAlertWithTitle:@"Your order"
message:@"Want some ice cream?"
cancelButton:@"No thanks"
otherButtons:@[@"Yes please!"]
buttonHandler:^(OHAlertView *alert, NSInteger buttonIndex)
{
NSLog(@"button tapped: %ld",(long)buttonIndex);

if (buttonIndex == alert.cancelButtonIndex)
{
self.status.text = @"Your order has been cancelled";
}
else
{
NSArray* flavors = [NSArray arrayWithObjects:@"chocolate",@"vanilla",@"strawberry",@"coffee",nil];
[OHAlertView showAlertWithTitle:@"Flavor"
message:@"Which flavor do you prefer?"
cancelButton:@"Cancel"
otherButtons:flavors
buttonHandler:^(OHAlertView *alert, NSInteger buttonIndex)
{
NSLog(@"button tapped: %ld",(long)buttonIndex);
if (buttonIndex == alert.cancelButtonIndex)
{
self.status.text = @"Your order has been cancelled";
}
else
{
NSString* flavor = [flavors objectAtIndex:(buttonIndex-alert.firstOtherButtonIndex)];
self.status.text = [NSString stringWithFormat:@"You ordered a %@ ice cream.",flavor];
}
}];
}
}];
}

-(IBAction)showAlert3WithTextField
{
OHAlertView *alert = [[OHAlertView alloc] initWithTitle:@"Email"
message:@"Enter a valid email [email protected]:"
cancelButton:@"Cancel"
otherButtons:@[@"OK"]
buttonHandler:^(OHAlertView *alert, NSInteger buttonIndex)
{
NSString* email = [alert textFieldAtIndex:0].text;
self.status.text = [NSString stringWithFormat:@"Email entered: %@", email];
}];

alert.alertViewStyle = UIAlertViewStylePlainTextInput;

NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9a-z+.-_]+@([0-9a-z]+\\.)+[0-9a-z]+"
options:NSRegularExpressionCaseInsensitive
error:nil];
[alert setShouldEnableFirstButton:^BOOL(OHAlertView* alert) {
NSString *email = [alert textFieldAtIndex:0].text;
return email && [regex numberOfMatchesInString:email options:0 range:NSMakeRange(0, email.length)] > 0;
}];

[alert show];
}

@end
Loading

0 comments on commit bc38906

Please sign in to comment.