From 1cc440ff3d377c5a5afe79d02edb018d73b44a07 Mon Sep 17 00:00:00 2001 From: Grigory Lutkov Date: Mon, 2 Nov 2015 20:19:28 +0300 Subject: [PATCH] Now LGAlertView combine UIAlertViewController, UIAlertView and UIActionSheet. Added new abilities. Fixed some bugs. --- .../LGAlertViewDemo.xcodeproj/project.pbxproj | 30 + Demo/LGAlertViewDemo/NavigationController.m | 2 + Demo/LGAlertViewDemo/TableViewController.m | 292 +-- .../TableViewControllerActionSheet.h | 13 + .../TableViewControllerActionSheet.m | 316 +++ .../TableViewControllerAlert.h | 13 + .../TableViewControllerAlert.m | 438 +++++ .../TableViewControllerCustomActionSheet.h | 13 + .../TableViewControllerCustomActionSheet.m | 276 +++ .../TableViewControllerCustomAlert.h | 13 + .../TableViewControllerCustomAlert.m | 244 +++ Demo/Podfile.lock | 4 +- LGAlertView.podspec | 6 +- LGAlertView/LGAlertView.h | 411 ++-- LGAlertView/LGAlertView.m | 1733 +++++++++++------ LGAlertView/LGAlertViewCell.h | 7 +- LGAlertView/LGAlertViewCell.m | 24 +- LGAlertView/LGAlertViewController.h | 17 + LGAlertView/LGAlertViewController.m | 95 + LGAlertView/LGAlertViewWindow.h | 34 + LGAlertView/LGAlertViewWindow.m | 34 + LGAlertView/UIWindow+LGAlertView.h | 15 + LGAlertView/UIWindow+LGAlertView.m | 28 + README.md | 112 +- 24 files changed, 3029 insertions(+), 1141 deletions(-) create mode 100644 Demo/LGAlertViewDemo/TableViewControllerActionSheet.h create mode 100644 Demo/LGAlertViewDemo/TableViewControllerActionSheet.m create mode 100644 Demo/LGAlertViewDemo/TableViewControllerAlert.h create mode 100644 Demo/LGAlertViewDemo/TableViewControllerAlert.m create mode 100644 Demo/LGAlertViewDemo/TableViewControllerCustomActionSheet.h create mode 100644 Demo/LGAlertViewDemo/TableViewControllerCustomActionSheet.m create mode 100644 Demo/LGAlertViewDemo/TableViewControllerCustomAlert.h create mode 100644 Demo/LGAlertViewDemo/TableViewControllerCustomAlert.m create mode 100644 LGAlertView/LGAlertViewController.h create mode 100644 LGAlertView/LGAlertViewController.m create mode 100644 LGAlertView/LGAlertViewWindow.h create mode 100644 LGAlertView/LGAlertViewWindow.m create mode 100644 LGAlertView/UIWindow+LGAlertView.h create mode 100644 LGAlertView/UIWindow+LGAlertView.m diff --git a/Demo/LGAlertViewDemo.xcodeproj/project.pbxproj b/Demo/LGAlertViewDemo.xcodeproj/project.pbxproj index f2b032c..d49999b 100644 --- a/Demo/LGAlertViewDemo.xcodeproj/project.pbxproj +++ b/Demo/LGAlertViewDemo.xcodeproj/project.pbxproj @@ -13,6 +13,10 @@ 4A3B788B1AD2A93D00DB8642 /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A3B788A1AD2A93D00DB8642 /* TableViewController.m */; }; 4A3B788E1AD2B29F00DB8642 /* NavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A3B788D1AD2B29F00DB8642 /* NavigationController.m */; }; 4ABF191C1BDA895200A12B6E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4ABF191B1BDA895200A12B6E /* LaunchScreen.storyboard */; }; + 4ACDE4C11BE10A4000CC8926 /* TableViewControllerAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 4ACDE4BE1BE10A4000CC8926 /* TableViewControllerAlert.m */; }; + 4ACDE4C21BE10A4000CC8926 /* TableViewControllerActionSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = 4ACDE4C01BE10A4000CC8926 /* TableViewControllerActionSheet.m */; }; + 4ACDE4C51BE10F7100CC8926 /* TableViewControllerCustomAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 4ACDE4C41BE10F7100CC8926 /* TableViewControllerCustomAlert.m */; }; + 4AEEC7541BE5381300ED5D90 /* TableViewControllerCustomActionSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = 4AEEC7531BE5381300ED5D90 /* TableViewControllerCustomActionSheet.m */; }; 92E830BBF9A0E9733AA1BC7E /* libPods-LGAlertViewDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 623B5C352E52555F577FBF72 /* libPods-LGAlertViewDemo.a */; }; /* End PBXBuildFile section */ @@ -28,6 +32,14 @@ 4A3B788C1AD2B29F00DB8642 /* NavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationController.h; sourceTree = ""; }; 4A3B788D1AD2B29F00DB8642 /* NavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationController.m; sourceTree = ""; }; 4ABF191B1BDA895200A12B6E /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; + 4ACDE4BD1BE10A4000CC8926 /* TableViewControllerAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewControllerAlert.h; sourceTree = ""; }; + 4ACDE4BE1BE10A4000CC8926 /* TableViewControllerAlert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewControllerAlert.m; sourceTree = ""; }; + 4ACDE4BF1BE10A4000CC8926 /* TableViewControllerActionSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewControllerActionSheet.h; sourceTree = ""; }; + 4ACDE4C01BE10A4000CC8926 /* TableViewControllerActionSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewControllerActionSheet.m; sourceTree = ""; }; + 4ACDE4C31BE10F7100CC8926 /* TableViewControllerCustomAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewControllerCustomAlert.h; sourceTree = ""; }; + 4ACDE4C41BE10F7100CC8926 /* TableViewControllerCustomAlert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewControllerCustomAlert.m; sourceTree = ""; }; + 4AEEC7521BE5381300ED5D90 /* TableViewControllerCustomActionSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewControllerCustomActionSheet.h; sourceTree = ""; }; + 4AEEC7531BE5381300ED5D90 /* TableViewControllerCustomActionSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewControllerCustomActionSheet.m; sourceTree = ""; }; 623B5C352E52555F577FBF72 /* libPods-LGAlertViewDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LGAlertViewDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 637E642E08EC55B4AF82AB1E /* Pods-LGAlertViewDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LGAlertViewDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LGAlertViewDemo/Pods-LGAlertViewDemo.debug.xcconfig"; sourceTree = ""; }; 75F4867B7B8225C0410A3B3A /* Pods-LGAlertViewDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LGAlertViewDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-LGAlertViewDemo/Pods-LGAlertViewDemo.release.xcconfig"; sourceTree = ""; }; @@ -72,6 +84,14 @@ 4A3B788D1AD2B29F00DB8642 /* NavigationController.m */, 4A3B78891AD2A93D00DB8642 /* TableViewController.h */, 4A3B788A1AD2A93D00DB8642 /* TableViewController.m */, + 4ACDE4BD1BE10A4000CC8926 /* TableViewControllerAlert.h */, + 4ACDE4BE1BE10A4000CC8926 /* TableViewControllerAlert.m */, + 4ACDE4BF1BE10A4000CC8926 /* TableViewControllerActionSheet.h */, + 4ACDE4C01BE10A4000CC8926 /* TableViewControllerActionSheet.m */, + 4ACDE4C31BE10F7100CC8926 /* TableViewControllerCustomAlert.h */, + 4ACDE4C41BE10F7100CC8926 /* TableViewControllerCustomAlert.m */, + 4AEEC7521BE5381300ED5D90 /* TableViewControllerCustomActionSheet.h */, + 4AEEC7531BE5381300ED5D90 /* TableViewControllerCustomActionSheet.m */, 4A3B78701AD2A28300DB8642 /* Images.xcassets */, 4A3B78631AD2A28200DB8642 /* Supporting Files */, 4ABF191B1BDA895200A12B6E /* LaunchScreen.storyboard */, @@ -225,8 +245,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4ACDE4C21BE10A4000CC8926 /* TableViewControllerActionSheet.m in Sources */, + 4ACDE4C51BE10F7100CC8926 /* TableViewControllerCustomAlert.m in Sources */, + 4AEEC7541BE5381300ED5D90 /* TableViewControllerCustomActionSheet.m in Sources */, 4A3B78691AD2A28200DB8642 /* AppDelegate.m in Sources */, 4A3B788E1AD2B29F00DB8642 /* NavigationController.m in Sources */, + 4ACDE4C11BE10A4000CC8926 /* TableViewControllerAlert.m in Sources */, 4A3B78661AD2A28200DB8642 /* main.m in Sources */, 4A3B788B1AD2A93D00DB8642 /* TableViewController.m in Sources */, ); @@ -320,11 +344,14 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = LGAlertViewDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 6.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.test.$(PRODUCT_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; }; name = Debug; }; @@ -334,11 +361,14 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = LGAlertViewDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 6.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.test.$(PRODUCT_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; }; name = Release; }; diff --git a/Demo/LGAlertViewDemo/NavigationController.m b/Demo/LGAlertViewDemo/NavigationController.m index b325123..f96c7e8 100644 --- a/Demo/LGAlertViewDemo/NavigationController.m +++ b/Demo/LGAlertViewDemo/NavigationController.m @@ -18,8 +18,10 @@ - (void)viewDidLoad { [super viewDidLoad]; + self.navigationBar.translucent = YES; self.navigationBar.barTintColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]}; + self.navigationBar.tintColor = [UIColor colorWithWhite:1.f alpha:0.5]; } - (BOOL)shouldAutorotate diff --git a/Demo/LGAlertViewDemo/TableViewController.m b/Demo/LGAlertViewDemo/TableViewController.m index 267e357..e8df175 100644 --- a/Demo/LGAlertViewDemo/TableViewController.m +++ b/Demo/LGAlertViewDemo/TableViewController.m @@ -7,7 +7,10 @@ // #import "TableViewController.h" -#import "LGAlertView.h" +#import "TableViewControllerAlert.h" +#import "TableViewControllerActionSheet.h" +#import "TableViewControllerCustomAlert.h" +#import "TableViewControllerCustomActionSheet.h" @interface TableViewController () @@ -24,19 +27,10 @@ - (id)init { self.title = @"LGAlertView"; - _titlesArray = @[@"UIAlertView", - @"LGAlertView + UIView", - @"LGAlertView + Buttons Short", - @"LGAlertView + Buttons Long", - @"LGAlertView + Buttons Multiline", - @"LGAlertView + Buttons (a lot of) 1", - @"LGAlertView + Buttons (a lot of) 2", - @"LGAlertView + No cancel gesture", - @"LGAlertView + TextFiled", - @"LGAlertView + TextFiled (a lot of)", - @"LGAlertView + ActivityIndicator", - @"LGAlertView + ProgressView", - @"LGAlertView + Crazy style"]; + _titlesArray = @[@"AlertView Style", + @"ActionSheet Style", + @"Custom AlertView Styles", + @"Custom ActionSheet Styles"]; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; } @@ -61,6 +55,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + cell.textLabel.font = [UIFont systemFontOfSize:16.f]; cell.textLabel.text = _titlesArray[indexPath.row]; @@ -76,278 +72,26 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath { if (indexPath.row == 0) { - [[[UIAlertView alloc] initWithTitle:@"Title" - message:@"Message" - delegate:nil - cancelButtonTitle:@"Cancel" - otherButtonTitles:@"Other 1", @"Other 2", @"Destructive", nil] show]; + TableViewControllerAlert *tableViewController = [TableViewControllerAlert new]; + [self.navigationController pushViewController:tableViewController animated:YES]; } else if (indexPath.row == 1) { - UIDatePicker *datePicker = [UIDatePicker new]; - datePicker.frame = CGRectMake(0.f, 0.f, datePicker.frame.size.width, 100.f); - - [[[LGAlertView alloc] initWithViewStyleWithTitle:@"WOW, it's DatePicker here" - message:@"Choose any date, please" - view:datePicker - buttonTitles:@[@"Done"] - cancelButtonTitle:@"Cancel" - destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + TableViewControllerActionSheet *tableViewController = [TableViewControllerActionSheet new]; + [self.navigationController pushViewController:tableViewController animated:YES]; } else if (indexPath.row == 2) { - [[[LGAlertView alloc] initWithTitle:@"Just title" - message:@"2 buttons in a row" - buttonTitles:nil - cancelButtonTitle:@"Cancel" - destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + TableViewControllerCustomAlert *tableViewController = [TableViewControllerCustomAlert new]; + [self.navigationController pushViewController:tableViewController animated:YES]; } else if (indexPath.row == 3) { - [[[LGAlertView alloc] initWithTitle:@"Some long title text, for iPhone 6 Plus even bigger." - message:@"Some really unbelievable long message text. And for iPhone 6 Plus it needs to be even bigger." - buttonTitles:@[@"Other button 1 with longest title text, for iPhone 6 Plus even bigger.", - @"Other button 2 with longest title text, for iPhone 6 Plus even bigger."] - cancelButtonTitle:@"Cancel" - destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil] showAnimated:YES completionHandler:nil]; - } - else if (indexPath.row == 4) - { - LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Some long title text, for iPhone 6 Plus even bigger." - message:@"Some really unbelievable long message text. And for iPhone 6 Plus it needs to be even bigger." - buttonTitles:@[@"Other button 1 with longest title text, for iPhone 6 Plus even bigger.", - @"Other button 2 with longest title text, for iPhone 6 Plus even bigger."] - cancelButtonTitle:@"Cancel" - destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; - alertView.buttonsNumberOfLines = 0; - [alertView showAnimated:YES completionHandler:nil]; - } - else if (indexPath.row == 5) - { - [[[LGAlertView alloc] initWithTitle:@"So many buttons..." - message:@"Scroll it" - buttonTitles:@[@"Other 1", - @"Other 2", - @"Other 3", - @"Other 4", - @"Other 5", - @"Other 6", - @"Other 7", - @"Other 8", - @"Other 9", - @"Other 10", - @"Other 12", - @"Other 13", - @"Other 14", - @"Other 15", - @"Other 16", - @"Other 17", - @"Other 18", - @"Other 19", - @"Other 20", - @"Other 21", - @"Other 22", - @"Other 23", - @"Other 24", - @"Other 25"] - cancelButtonTitle:@"Cancel" - destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil] showAnimated:YES completionHandler:nil]; - } - else if (indexPath.row == 6) - { - LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"So many buttons..." - message:@"Scroll it" - buttonTitles:@[@"Other 1", - @"Other 2", - @"Other 3", - @"Other 4", - @"Other 5", - @"Other 6", - @"Other 7", - @"Other 8", - @"Other 9", - @"Other 10", - @"Other 12", - @"Other 13", - @"Other 14", - @"Other 15"] - cancelButtonTitle:@"Cancel" - destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; - alertView.heightMax = 200.f; - [alertView showAnimated:YES completionHandler:nil]; - } - else if (indexPath.row == 7) - { - LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"No cancel here" - message:@"You need to make a decision" - buttonTitles:@[@"Blue pill"] - cancelButtonTitle:nil - destructiveButtonTitle:@"Red pill" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; - - alertView.cancelOnTouch = NO; - [alertView showAnimated:YES completionHandler:nil]; - } - else if (indexPath.row == 8) - { - LGAlertView *alertView = [[LGAlertView alloc] initWithTextFieldsStyleWithTitle:@"Security" - message:@"Enter your login and password" - numberOfTextFields:2 - textFieldsSetupHandler:^(UITextField *textField, NSUInteger index) - { - if (index == 0) - textField.placeholder = @"Login"; - else if (index == 1) - { - textField.placeholder = @"Password"; - textField.secureTextEntry = YES; - } - } - buttonTitles:@[@"Done"] - cancelButtonTitle:@"Cancel" - destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; - alertView.cancelOnTouch = NO; - [alertView showAnimated:YES completionHandler:nil]; - } - else if (indexPath.row == 9) - { - LGAlertView *alertView = [[LGAlertView alloc] initWithTextFieldsStyleWithTitle:@"So many textFields..." - message:@"When you select some, alertView will change size" - numberOfTextFields:15 - textFieldsSetupHandler:^(UITextField *textField, NSUInteger index) - { - textField.placeholder = [NSString stringWithFormat:@"Beautiful placeholder %i", (int)index+1]; - } - buttonTitles:@[@"Done"] - cancelButtonTitle:@"Cancel" - destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; - alertView.cancelOnTouch = NO; - [alertView showAnimated:YES completionHandler:nil]; - } - else if (indexPath.row == 10) - { - LGAlertView *alertView = [[LGAlertView alloc] initWithActivityIndicatorStyleWithTitle:@"Loading" - message:@"Waiting please" - buttonTitles:nil - cancelButtonTitle:@"I'm hurry" - destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; - alertView.cancelOnTouch = NO; - [alertView showAnimated:YES completionHandler:nil]; - } - else if (indexPath.row == 11) - { - LGAlertView *alertView = [[LGAlertView alloc] initWithProgressViewStyleWithTitle:@"Loading" - message:@"Waiting please" - progressLabelText:@"0 %" - buttonTitles:nil - cancelButtonTitle:@"I'm hurry" - destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; - alertView.cancelOnTouch = NO; - [alertView showAnimated:YES completionHandler:nil]; - - [self updateProgressWithAlertView:alertView]; - } - else if (indexPath.row == 12) - { - LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"CRAZY STYLE" - message:@"May be someone like it?" - buttonTitles:@[@"Awesome Button"] - cancelButtonTitle:@"Cancel" - destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; - - alertView.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.8]; - alertView.offsetVertical = 0; - alertView.buttonsHeight = 64.f; - alertView.width = CGFLOAT_MAX; - - alertView.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.8]; - alertView.layerBorderWidth = 1.f; - alertView.layerBorderColor = [UIColor redColor]; - alertView.layerCornerRadius = 0.f; - alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.5]; - alertView.layerShadowRadius = 5.f; - - alertView.titleTextAlignment = NSTextAlignmentRight; - alertView.titleTextColor = [UIColor whiteColor]; - - alertView.messageTextAlignment = NSTextAlignmentLeft; - alertView.messageTextColor = [UIColor whiteColor]; - - alertView.separatorsColor = [UIColor colorWithWhite:0.6 alpha:1.f]; - - alertView.tintColor = [UIColor greenColor]; - - alertView.buttonsTitleColorHighlighted = [UIColor blackColor]; - - alertView.cancelButtonTitleColor = [UIColor cyanColor]; - alertView.cancelButtonTitleColorHighlighted = [UIColor blackColor]; - alertView.cancelButtonBackgroundColorHighlighted = [UIColor cyanColor]; - - alertView.destructiveButtonTitleColor = [UIColor yellowColor]; - alertView.destructiveButtonTitleColorHighlighted = [UIColor blackColor]; - alertView.destructiveButtonBackgroundColorHighlighted = [UIColor yellowColor]; - - // And much more settings you can apply, check it in LGAlertView class - - [alertView showAnimated:YES completionHandler:nil]; + TableViewControllerCustomActionSheet *tableViewController = [TableViewControllerCustomActionSheet new]; + [self.navigationController pushViewController:tableViewController animated:YES]; } [tableView deselectRowAtIndexPath:indexPath animated:YES]; } -- (void)updateProgressWithAlertView:(LGAlertView *)alertView -{ - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) - { - if (alertView.progress >= 1.f) - [alertView dismissAnimated:YES completionHandler:nil]; - else - { - float progress = alertView.progress+0.0025; - - if (progress > 1.f) - progress = 1.f; - - [alertView setProgress:progress progressLabelText:[NSString stringWithFormat:@"%.0f %%", progress*100]]; - - [self updateProgressWithAlertView:alertView]; - } - }); -} - @end diff --git a/Demo/LGAlertViewDemo/TableViewControllerActionSheet.h b/Demo/LGAlertViewDemo/TableViewControllerActionSheet.h new file mode 100644 index 0000000..c89a34a --- /dev/null +++ b/Demo/LGAlertViewDemo/TableViewControllerActionSheet.h @@ -0,0 +1,13 @@ +// +// TableViewControllerActionSheet.h +// LGAlertViewDemo +// +// Created by Grigory Lutkov on 28.10.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import + +@interface TableViewControllerActionSheet : UITableViewController + +@end diff --git a/Demo/LGAlertViewDemo/TableViewControllerActionSheet.m b/Demo/LGAlertViewDemo/TableViewControllerActionSheet.m new file mode 100644 index 0000000..2942946 --- /dev/null +++ b/Demo/LGAlertViewDemo/TableViewControllerActionSheet.m @@ -0,0 +1,316 @@ +// +// TableViewControllerActionSheet.m +// LGAlertViewDemo +// +// Created by Grigory Lutkov on 28.10.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import "TableViewControllerActionSheet.h" +#import "LGAlertView.h" + +@interface TableViewControllerActionSheet () + +@property (strong, nonatomic) NSArray *titlesArray; + +@end + +@implementation TableViewControllerActionSheet + +- (id)init +{ + self = [super initWithStyle:UITableViewStylePlain]; + if (self) + { + self.title = @"ActionSheet Style"; + + _titlesArray = @[@"UIActionSheet + 4 Buttons", + @"UIAlertController + 4 Buttons", + @"", + @"LGAlertView + 4 Buttons", + @"LGAlertView + Long texts adjusted", + @"LGAlertView + Long texts multiline", + @"LGAlertView + No cancel gesture", + @"LGAlertView + A lot of buttons long", + @"LGAlertView + A lot of buttons short", + @"LGAlertView + UIView", + @"LGAlertView + ActivityIndicator", + @"LGAlertView + ProgressView"]; + + [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; + UIEdgeInsets contentInset = self.tableView.contentInset; + contentInset.bottom = 44.f*2; + self.tableView.contentInset = contentInset; + } + return self; +} + +#pragma mark - UITableView DataSource + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return _titlesArray.count; +} + +#pragma mark - UITableView Delegate + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; + + cell.textLabel.font = [UIFont systemFontOfSize:16.f]; + cell.textLabel.text = _titlesArray[indexPath.row]; + + cell.userInteractionEnabled = (indexPath.row != 2); + + return cell; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return 44.f; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (indexPath.row == 0) + { + [[[UIActionSheet alloc] initWithTitle:@"Title" + delegate:nil + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + otherButtonTitles:@"Button 1", @"Button 2", nil] showInView:self.view]; + } + else if (indexPath.row == 1) + { + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" + message:@"Message" + preferredStyle:UIAlertControllerStyleActionSheet]; + UIAlertAction *cancelButton = [UIAlertAction actionWithTitle:@"Cancel" + style:UIAlertActionStyleCancel + handler:nil]; + UIAlertAction *destructiveButton = [UIAlertAction actionWithTitle:@"Destructive" + style:UIAlertActionStyleDestructive + handler:nil]; + UIAlertAction *otherButton1 = [UIAlertAction actionWithTitle:@"Button 1" + style:UIAlertActionStyleDefault + handler:nil]; + UIAlertAction *otherButton2 = [UIAlertAction actionWithTitle:@"Button 2" + style:UIAlertActionStyleDefault + handler:nil]; + [alertController addAction:cancelButton]; + [alertController addAction:destructiveButton]; + [alertController addAction:otherButton1]; + [alertController addAction:otherButton2]; + + [self presentViewController:alertController animated:YES completion:nil]; + } + else if (indexPath.row == 3) + { + [[[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button 1", @"Button 2"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 4) + { + [[[LGAlertView alloc] initWithTitle:@"Some very really unbelievable long title text. For iPhone 6 and 6 Plus is even longer." + message:@"Some unbelievable really very long message text. For iPhone 6 and 6 Plus is even longer." + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Other button 1 with longest title text ever exists. For iPhone 6 and 6 Plus is even longer.", + @"Other button 2 with longest title text ever exists. For iPhone 6 and 6 Plus is even longer."] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 5) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Some very really unbelievable long title text. For iPhone 6 and 6 Plus is even longer." + message:@"Some unbelievable really very long message text. For iPhone 6 and 6 Plus is even longer." + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Other button 1 with longest title text ever exists. For iPhone 6 and 6 Plus is even longer.", + @"Other button 2 with longest title text ever exists. For iPhone 6 and 6 Plus is even longer."] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + alertView.buttonsNumberOfLines = 0; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 6) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"No cancel here" + message:@"You need to make a decision" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Blue pill"] + cancelButtonTitle:nil + destructiveButtonTitle:@"Red pill" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + alertView.cancelOnTouch = NO; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 7) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"A lot of buttons" + message:@"You can scroll it" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button 1", + @"Button 2", + @"Button 3", + @"Button 4", + @"Button 5", + @"Button 6", + @"Button 7", + @"Button 8", + @"Button 9", + @"Button 10", + @"Button 12", + @"Button 13", + @"Button 14", + @"Button 15", + @"Button 16", + @"Button 17", + @"Button 18", + @"Button 19", + @"Button 20", + @"Button 21", + @"Button 22", + @"Button 23", + @"Button 24", + @"Button 25"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + alertView.windowLevel = LGAlertViewWindowLevelBelowStatusBar; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 8) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"A lot of buttons" + message:@"You can scroll it" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button 1", + @"Button 2", + @"Button 3", + @"Button 4", + @"Button 5", + @"Button 6", + @"Button 7", + @"Button 8", + @"Button 9", + @"Button 10", + @"Button 12", + @"Button 13", + @"Button 14", + @"Button 15", + @"Button 16", + @"Button 17", + @"Button 18", + @"Button 19", + @"Button 20", + @"Button 21", + @"Button 22", + @"Button 23", + @"Button 24", + @"Button 25"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + alertView.heightMax = 256.f; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 9) + { + UIDatePicker *datePicker = [UIDatePicker new]; + datePicker.datePickerMode = UIDatePickerModeTime; + datePicker.frame = CGRectMake(0.f, 0.f, self.view.frame.size.width, 110.f); + + [[[LGAlertView alloc] initWithViewAndTitle:@"WOW, it's DatePicker here" + message:@"Choose any time, please" + style:LGAlertViewStyleActionSheet + view:datePicker + buttonTitles:@[@"Done"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:nil + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 10) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithActivityIndicatorAndTitle:@"Loading" + message:@"Waiting please" + style:LGAlertViewStyleActionSheet + buttonTitles:nil + cancelButtonTitle:@"I'm hurry" + destructiveButtonTitle:nil + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + [alertView showAnimated:YES completionHandler:nil]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) + { + [alertView dismissAnimated:YES completionHandler:nil]; + }); + } + else if (indexPath.row == 11) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithProgressViewAndTitle:@"Loading" + message:@"Waiting please" + style:LGAlertViewStyleActionSheet + progressLabelText:@"0 %" + buttonTitles:nil + cancelButtonTitle:@"I'm hurry" + destructiveButtonTitle:nil + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + [alertView showAnimated:YES completionHandler:nil]; + + [self updateProgressWithAlertView:alertView]; + } + + [tableView deselectRowAtIndexPath:indexPath animated:YES]; +} + +- (void)updateProgressWithAlertView:(LGAlertView *)alertView +{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) + { + if (alertView.progress >= 1.f) + [alertView dismissAnimated:YES completionHandler:nil]; + else + { + float progress = alertView.progress+0.0025; + + if (progress > 1.f) + progress = 1.f; + + [alertView setProgress:progress progressLabelText:[NSString stringWithFormat:@"%.0f %%", progress*100]]; + + [self updateProgressWithAlertView:alertView]; + } + }); +} + +@end diff --git a/Demo/LGAlertViewDemo/TableViewControllerAlert.h b/Demo/LGAlertViewDemo/TableViewControllerAlert.h new file mode 100644 index 0000000..5fccb0f --- /dev/null +++ b/Demo/LGAlertViewDemo/TableViewControllerAlert.h @@ -0,0 +1,13 @@ +// +// TableViewControllerAlert.h +// LGAlertViewDemo +// +// Created by Grigory Lutkov on 28.10.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import + +@interface TableViewControllerAlert : UITableViewController + +@end diff --git a/Demo/LGAlertViewDemo/TableViewControllerAlert.m b/Demo/LGAlertViewDemo/TableViewControllerAlert.m new file mode 100644 index 0000000..95d9418 --- /dev/null +++ b/Demo/LGAlertViewDemo/TableViewControllerAlert.m @@ -0,0 +1,438 @@ +// +// TableViewControllerAlert.m +// LGAlertViewDemo +// +// Created by Grigory Lutkov on 28.10.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import "TableViewControllerAlert.h" +#import "LGAlertView.h" + +@interface TableViewControllerAlert () + +@property (strong, nonatomic) NSArray *titlesArray; +@property (strong, nonatomic) LGAlertView *securityAlertView; + +@end + +@implementation TableViewControllerAlert + +- (id)init +{ + self = [super initWithStyle:UITableViewStylePlain]; + if (self) + { + self.title = @"AlertView Style"; + + _titlesArray = @[@"UIAlertView + 4 Buttons", + @"UIAlertController + 4 Buttons", + @"", + @"LGAlertView + 1 Button", + @"LGAlertView + 2 Buttons in a row", + @"LGAlertView + 3 Buttons in a row", + @"LGAlertView + 4 Buttons", + @"LGAlertView + Long texts adjusted", + @"LGAlertView + Long texts multiline", + @"LGAlertView + No cancel gesture", + @"LGAlertView + A lot of buttons long", + @"LGAlertView + A lot of buttons short", + @"LGAlertView + TextFileds", + @"LGAlertView + A lot of textFields", + @"LGAlertView + UIView", + @"LGAlertView + ActivityIndicator", + @"LGAlertView + ProgressView"]; + + [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; + UIEdgeInsets contentInset = self.tableView.contentInset; + contentInset.bottom = 44.f*2; + self.tableView.contentInset = contentInset; + } + return self; +} + +#pragma mark - UITableView DataSource + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return _titlesArray.count; +} + +#pragma mark - UITableView Delegate + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; + + cell.textLabel.font = [UIFont systemFontOfSize:16.f]; + cell.textLabel.text = _titlesArray[indexPath.row]; + + cell.userInteractionEnabled = (indexPath.row != 2); + + return cell; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return 44.f; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (indexPath.row == 0) + { + [[[UIAlertView alloc] initWithTitle:@"Title" + message:@"Message" + delegate:nil + cancelButtonTitle:@"Cancel" + otherButtonTitles:@"Button 1", @"Button 2", @"Destructive", nil] show]; + } + else if (indexPath.row == 1) + { + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" + message:@"Message" + preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction *cancelButton = [UIAlertAction actionWithTitle:@"Cancel" + style:UIAlertActionStyleCancel + handler:nil]; + UIAlertAction *destructiveButton = [UIAlertAction actionWithTitle:@"Destructive" + style:UIAlertActionStyleDestructive + handler:nil]; + UIAlertAction *otherButton1 = [UIAlertAction actionWithTitle:@"Button 1" + style:UIAlertActionStyleDefault + handler:nil]; + UIAlertAction *otherButton2 = [UIAlertAction actionWithTitle:@"Button 2" + style:UIAlertActionStyleDefault + handler:nil]; + [alertController addAction:cancelButton]; + [alertController addAction:destructiveButton]; + [alertController addAction:otherButton1]; + [alertController addAction:otherButton2]; + + [self presentViewController:alertController animated:YES completion:nil]; + } + else if (indexPath.row == 3) + { + [[[LGAlertView alloc] initWithTitle:@"Title" + message:@"1 button" + style:LGAlertViewStyleAlert + buttonTitles:nil + cancelButtonTitle:@"OK" + destructiveButtonTitle:nil + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 4) + { + [[[LGAlertView alloc] initWithTitle:@"Title" + message:@"2 buttons in a row" + style:LGAlertViewStyleAlert + buttonTitles:nil + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 5) + { + [[[LGAlertView alloc] initWithTitle:@"Title" + message:@"3 buttons in a row" + style:LGAlertViewStyleAlert + buttonTitles:@[@"1 - A", @"2 - B", @"3 - C"] + cancelButtonTitle:nil + destructiveButtonTitle:nil + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 6) + { + [[[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Button 1", @"Button 2"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 7) + { + [[[LGAlertView alloc] initWithTitle:@"Some very really unbelievable long title text" + message:@"Some unbelievable really very long message text" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Other button 1 with longest title text ever exists", + @"Other button 2 with longest title text ever exists"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 8) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Some very really unbelievable long title text" + message:@"Some unbelievable really very long message text" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Other button 1 with longest title text ever exists", + @"Other button 2 with longest title text ever exists"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + alertView.buttonsNumberOfLines = 0; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 9) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"No cancel here" + message:@"You need to make a decision" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Blue pill"] + cancelButtonTitle:nil + destructiveButtonTitle:@"Red pill" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + alertView.cancelOnTouch = NO; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 10) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"A lot of buttons" + message:@"You can scroll it" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Button 1", + @"Button 2", + @"Button 3", + @"Button 4", + @"Button 5", + @"Button 6", + @"Button 7", + @"Button 8", + @"Button 9", + @"Button 10", + @"Button 12", + @"Button 13", + @"Button 14", + @"Button 15", + @"Button 16", + @"Button 17", + @"Button 18", + @"Button 19", + @"Button 20", + @"Button 21", + @"Button 22", + @"Button 23", + @"Button 24", + @"Button 25"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + alertView.windowLevel = LGAlertViewWindowLevelBelowStatusBar; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 11) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"A lot of buttons" + message:@"You can scroll it" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Button 1", + @"Button 2", + @"Button 3", + @"Button 4", + @"Button 5", + @"Button 6", + @"Button 7", + @"Button 8", + @"Button 9", + @"Button 10", + @"Button 12", + @"Button 13", + @"Button 14", + @"Button 15", + @"Button 16", + @"Button 17", + @"Button 18", + @"Button 19", + @"Button 20", + @"Button 21", + @"Button 22", + @"Button 23", + @"Button 24", + @"Button 25"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + alertView.heightMax = 256.f; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 12) + { + _securityAlertView = [[LGAlertView alloc] initWithTextFieldsAndTitle:@"Security" + message:@"Enter your login and password" + numberOfTextFields:2 + textFieldsSetupHandler:^(UITextField *textField, NSUInteger index) + { + if (index == 0) + textField.placeholder = @"Login"; + else if (index == 1) + { + textField.placeholder = @"Password"; + textField.secureTextEntry = YES; + } + + textField.tag = index; + textField.delegate = self; + textField.enablesReturnKeyAutomatically = YES; + textField.autocapitalizationType = NO; + textField.autocorrectionType = NO; + } + buttonTitles:@[@"Done"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:nil + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + [_securityAlertView setButtonAtIndex:0 enabled:NO]; + [_securityAlertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 13) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTextFieldsAndTitle:@"A lot of textFields" + message:@"When you select some, alertView will change size" + numberOfTextFields:25 + textFieldsSetupHandler:^(UITextField *textField, NSUInteger index) + { + textField.placeholder = [NSString stringWithFormat:@"Placeholder %lu", index+1]; + } + buttonTitles:@[@"Done"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:nil + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + alertView.windowLevel = LGAlertViewWindowLevelBelowStatusBar; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 14) + { + UIDatePicker *datePicker = [UIDatePicker new]; + datePicker.datePickerMode = UIDatePickerModeTime; + datePicker.frame = CGRectMake(0.f, 0.f, datePicker.frame.size.width, 160.f); + + [[[LGAlertView alloc] initWithViewAndTitle:@"WOW, it's DatePicker here" + message:@"Choose any time, please" + style:LGAlertViewStyleAlert + view:datePicker + buttonTitles:@[@"Done"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:nil + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 15) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithActivityIndicatorAndTitle:@"Loading" + message:@"Waiting please" + style:LGAlertViewStyleAlert + buttonTitles:nil + cancelButtonTitle:@"I'm hurry" + destructiveButtonTitle:nil + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + [alertView showAnimated:YES completionHandler:nil]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) + { + [alertView dismissAnimated:YES completionHandler:nil]; + }); + } + else if (indexPath.row == 16) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithProgressViewAndTitle:@"Loading" + message:@"Waiting please" + style:LGAlertViewStyleAlert + progressLabelText:@"0 %" + buttonTitles:nil + cancelButtonTitle:@"I'm hurry" + destructiveButtonTitle:nil + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + [alertView showAnimated:YES completionHandler:nil]; + + [self updateProgressWithAlertView:alertView]; + } + + [tableView deselectRowAtIndexPath:indexPath animated:YES]; +} + +#pragma mark - UITextField Delegate + +- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string +{ + UITextField *secondTextField = _securityAlertView.textFieldsArray[(textField.tag == 0 ? 1 : 0)]; + + NSMutableString *currentString = textField.text.mutableCopy; + + [currentString replaceCharactersInRange:range withString:string]; + + [_securityAlertView setButtonAtIndex:0 enabled:(currentString.length > 2 && secondTextField.text.length > 2)]; + + return YES; +} + +- (BOOL)textFieldShouldReturn:(UITextField *)textField +{ + if (textField.tag < 1) + [_securityAlertView.textFieldsArray[(textField.tag + 1)] becomeFirstResponder]; + else + { + if ([_securityAlertView isButtonEnabledAtIndex:0]) + [_securityAlertView dismissAnimated:YES completionHandler:nil]; + else + [textField resignFirstResponder]; + } + + return YES; +} + +#pragma mark - + +- (void)updateProgressWithAlertView:(LGAlertView *)alertView +{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) + { + if (alertView.progress >= 1.f) + [alertView dismissAnimated:YES completionHandler:nil]; + else + { + float progress = alertView.progress+0.0025; + + if (progress > 1.f) + progress = 1.f; + + [alertView setProgress:progress progressLabelText:[NSString stringWithFormat:@"%.0f %%", progress*100]]; + + [self updateProgressWithAlertView:alertView]; + } + }); +} + +@end diff --git a/Demo/LGAlertViewDemo/TableViewControllerCustomActionSheet.h b/Demo/LGAlertViewDemo/TableViewControllerCustomActionSheet.h new file mode 100644 index 0000000..2202abc --- /dev/null +++ b/Demo/LGAlertViewDemo/TableViewControllerCustomActionSheet.h @@ -0,0 +1,13 @@ +// +// TableViewControllerCustomActionSheet.h +// LGAlertViewDemo +// +// Created by Grigory Lutkov on 28.10.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import + +@interface TableViewControllerCustomActionSheet : UITableViewController + +@end diff --git a/Demo/LGAlertViewDemo/TableViewControllerCustomActionSheet.m b/Demo/LGAlertViewDemo/TableViewControllerCustomActionSheet.m new file mode 100644 index 0000000..570e9f0 --- /dev/null +++ b/Demo/LGAlertViewDemo/TableViewControllerCustomActionSheet.m @@ -0,0 +1,276 @@ +// +// TableViewControllerCustomActionSheet.m +// LGAlertViewDemo +// +// Created by Grigory Lutkov on 28.10.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import "TableViewControllerCustomActionSheet.h" +#import "LGAlertView.h" + +@interface TableViewControllerCustomActionSheet () + +@property (strong, nonatomic) NSArray *titlesArray; + +@end + +@implementation TableViewControllerCustomActionSheet + +- (id)init +{ + self = [super initWithStyle:UITableViewStylePlain]; + if (self) + { + self.title = @"Custom ActionSheet Styles"; + + _titlesArray = @[@"Default Style", + @"", + @"Custom Style 1", + @"Custom Style 2", + @"Custom Style 3", + @"Custom Style 4", + @"Custom Style 5", + @"Custom Style 6"]; + + [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; + } + return self; +} + +#pragma mark - UITableView DataSource + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return _titlesArray.count; +} + +#pragma mark - UITableView Delegate + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; + + cell.textLabel.font = [UIFont systemFontOfSize:16.f]; + cell.textLabel.text = _titlesArray[indexPath.row]; + + cell.userInteractionEnabled = (indexPath.row != 1); + + return cell; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return 44.f; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (indexPath.row == 0) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 2) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + alertView.coverColor = [UIColor colorWithWhite:1.f alpha:0.9]; + alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.3]; + alertView.layerShadowRadius = 4.f; + alertView.buttonsHeight = 44.f; + alertView.titleFont = [UIFont boldSystemFontOfSize:18.f]; + alertView.titleTextColor = [UIColor blackColor]; + alertView.messageTextColor = [UIColor blackColor]; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 3) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + alertView.coverColor = [UIColor colorWithWhite:1.f alpha:0.9]; + alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.3]; + alertView.layerShadowRadius = 4.f; + alertView.layerCornerRadius = 0.f; + alertView.layerBorderWidth = 2.f; + alertView.layerBorderColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + alertView.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.7]; + alertView.buttonsHeight = 44.f; + alertView.titleFont = [UIFont boldSystemFontOfSize:18.f]; + alertView.titleTextColor = [UIColor blackColor]; + alertView.messageTextColor = [UIColor blackColor]; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 4) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + alertView.coverColor = [UIColor colorWithWhite:1.f alpha:0.9]; + alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.3]; + alertView.layerShadowRadius = 4.f; + alertView.layerCornerRadius = 0.f; + alertView.layerBorderWidth = 2.f; + alertView.layerBorderColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + alertView.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.7]; + alertView.buttonsHeight = 44.f; + alertView.titleFont = [UIFont boldSystemFontOfSize:18.f]; + alertView.titleTextColor = [UIColor blackColor]; + alertView.messageTextColor = [UIColor blackColor]; + alertView.width = MIN(self.view.bounds.size.width, self.view.bounds.size.height); + alertView.offsetVertical = 0.f; + alertView.cancelButtonOffset = 0.f; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 5) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + alertView.coverColor = [UIColor colorWithWhite:1.f alpha:0.9]; + alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.3]; + alertView.layerShadowRadius = 4.f; + alertView.layerCornerRadius = 0.f; + alertView.layerBorderWidth = 2.f; + alertView.layerBorderColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + alertView.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.7]; + alertView.buttonsHeight = 44.f; + alertView.titleFont = [UIFont boldSystemFontOfSize:18.f]; + alertView.titleTextColor = [UIColor blackColor]; + alertView.messageTextColor = [UIColor blackColor]; + alertView.width = MIN(self.view.bounds.size.width, self.view.bounds.size.height); + alertView.offsetVertical = 0.f; + alertView.cancelButtonOffset = 0.f; + alertView.titleTextAlignment = NSTextAlignmentLeft; + alertView.messageTextAlignment = NSTextAlignmentLeft; + alertView.buttonsTextAlignment = NSTextAlignmentRight; + alertView.cancelButtonTextAlignment = NSTextAlignmentRight; + alertView.destructiveButtonTextAlignment = NSTextAlignmentRight; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 6) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + alertView.coverColor = [UIColor colorWithWhite:1.f alpha:0.9]; + alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.3]; + alertView.layerShadowRadius = 4.f; + alertView.layerCornerRadius = 0.f; + alertView.layerBorderWidth = 2.f; + alertView.layerBorderColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + alertView.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.7]; + alertView.buttonsHeight = 44.f; + alertView.titleFont = [UIFont boldSystemFontOfSize:18.f]; + alertView.titleTextColor = [UIColor blackColor]; + alertView.messageTextColor = [UIColor blackColor]; + alertView.width = MIN(self.view.bounds.size.width, self.view.bounds.size.height); + alertView.offsetVertical = 0.f; + alertView.cancelButtonOffset = 0.f; + alertView.titleTextAlignment = NSTextAlignmentLeft; + alertView.messageTextAlignment = NSTextAlignmentLeft; + alertView.destructiveButtonTextAlignment = NSTextAlignmentRight; + alertView.buttonsTextAlignment = NSTextAlignmentRight; + alertView.cancelButtonTextAlignment = NSTextAlignmentRight; + alertView.separatorsColor = nil; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 7) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + alertView.coverColor = [UIColor colorWithWhite:1.f alpha:0.9]; + alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.3]; + alertView.layerShadowRadius = 4.f; + alertView.layerCornerRadius = 0.f; + alertView.layerBorderWidth = 2.f; + alertView.layerBorderColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + alertView.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.7]; + alertView.buttonsHeight = 44.f; + alertView.titleFont = [UIFont boldSystemFontOfSize:18.f]; + alertView.titleTextColor = [UIColor blackColor]; + alertView.messageTextColor = [UIColor blackColor]; + alertView.width = MIN(self.view.bounds.size.width, self.view.bounds.size.height); + alertView.offsetVertical = 0.f; + alertView.cancelButtonOffset = 0.f; + alertView.titleTextAlignment = NSTextAlignmentLeft; + alertView.messageTextAlignment = NSTextAlignmentLeft; + alertView.destructiveButtonTextAlignment = NSTextAlignmentRight; + alertView.buttonsTextAlignment = NSTextAlignmentRight; + alertView.cancelButtonTextAlignment = NSTextAlignmentRight; + alertView.separatorsColor = nil; + alertView.destructiveButtonTitleColor = [UIColor whiteColor]; + alertView.buttonsTitleColor = [UIColor whiteColor]; + alertView.cancelButtonTitleColor = [UIColor whiteColor]; + alertView.destructiveButtonBackgroundColor = [UIColor colorWithRed:1.f green:0.f blue:0.f alpha:0.5]; + alertView.buttonsBackgroundColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:0.5]; + alertView.cancelButtonBackgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5]; + alertView.destructiveButtonBackgroundColorHighlighted = [UIColor colorWithRed:1.f green:0.f blue:0.f alpha:1.f]; + alertView.buttonsBackgroundColorHighlighted = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + alertView.cancelButtonBackgroundColorHighlighted = [UIColor colorWithWhite:0.5 alpha:1.f]; + [alertView showAnimated:YES completionHandler:nil]; + } + + [tableView deselectRowAtIndexPath:indexPath animated:YES]; +} + +@end diff --git a/Demo/LGAlertViewDemo/TableViewControllerCustomAlert.h b/Demo/LGAlertViewDemo/TableViewControllerCustomAlert.h new file mode 100644 index 0000000..2da147f --- /dev/null +++ b/Demo/LGAlertViewDemo/TableViewControllerCustomAlert.h @@ -0,0 +1,13 @@ +// +// TableViewControllerCustomAlert.h +// LGAlertViewDemo +// +// Created by Grigory Lutkov on 28.10.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import + +@interface TableViewControllerCustomAlert : UITableViewController + +@end diff --git a/Demo/LGAlertViewDemo/TableViewControllerCustomAlert.m b/Demo/LGAlertViewDemo/TableViewControllerCustomAlert.m new file mode 100644 index 0000000..ead5b24 --- /dev/null +++ b/Demo/LGAlertViewDemo/TableViewControllerCustomAlert.m @@ -0,0 +1,244 @@ +// +// TableViewControllerCustomAlert.m +// LGAlertViewDemo +// +// Created by Grigory Lutkov on 28.10.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import "TableViewControllerCustomAlert.h" +#import "LGAlertView.h" + +@interface TableViewControllerCustomAlert () + +@property (strong, nonatomic) NSArray *titlesArray; + +@end + +@implementation TableViewControllerCustomAlert + +- (id)init +{ + self = [super initWithStyle:UITableViewStylePlain]; + if (self) + { + self.title = @"Custom AlertView Styles"; + + _titlesArray = @[@"Default Style", + @"", + @"Custom Style 1", + @"Custom Style 2", + @"Custom Style 3", + @"Custom Style 4", + @"Custom Style 5", + @"Custom Style 6"]; + + [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; + } + return self; +} + +#pragma mark - UITableView DataSource + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return _titlesArray.count; +} + +#pragma mark - UITableView Delegate + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; + + cell.textLabel.font = [UIFont systemFontOfSize:16.f]; + cell.textLabel.text = _titlesArray[indexPath.row]; + + cell.userInteractionEnabled = (indexPath.row != 1); + + return cell; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return 44.f; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + if (indexPath.row == 0) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 2) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + alertView.coverColor = [UIColor colorWithWhite:1.f alpha:0.9]; + alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.3]; + alertView.layerShadowRadius = 4.f; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 3) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + alertView.coverColor = [UIColor colorWithWhite:1.f alpha:0.9]; + alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.3]; + alertView.layerShadowRadius = 4.f; + alertView.layerCornerRadius = 0.f; + alertView.layerBorderWidth = 2.f; + alertView.layerBorderColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + alertView.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.7]; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 4) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + alertView.coverColor = [UIColor colorWithWhite:1.f alpha:0.9]; + alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.3]; + alertView.layerShadowRadius = 4.f; + alertView.layerCornerRadius = 0.f; + alertView.layerBorderWidth = 2.f; + alertView.layerBorderColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + alertView.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.7]; + alertView.width = MIN(self.view.bounds.size.width, self.view.bounds.size.height); + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 5) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + alertView.coverColor = [UIColor colorWithWhite:1.f alpha:0.9]; + alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.3]; + alertView.layerShadowRadius = 4.f; + alertView.layerCornerRadius = 0.f; + alertView.layerBorderWidth = 2.f; + alertView.layerBorderColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + alertView.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.7]; + alertView.width = MIN(self.view.bounds.size.width, self.view.bounds.size.height); + alertView.titleTextAlignment = NSTextAlignmentLeft; + alertView.messageTextAlignment = NSTextAlignmentLeft; + alertView.buttonsTextAlignment = NSTextAlignmentRight; + alertView.cancelButtonTextAlignment = NSTextAlignmentRight; + alertView.destructiveButtonTextAlignment = NSTextAlignmentRight; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 6) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + alertView.coverColor = [UIColor colorWithWhite:1.f alpha:0.9]; + alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.3]; + alertView.layerShadowRadius = 4.f; + alertView.layerCornerRadius = 0.f; + alertView.layerBorderWidth = 2.f; + alertView.layerBorderColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + alertView.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.7]; + alertView.width = MIN(self.view.bounds.size.width, self.view.bounds.size.height); + alertView.titleTextAlignment = NSTextAlignmentLeft; + alertView.messageTextAlignment = NSTextAlignmentLeft; + alertView.destructiveButtonTextAlignment = NSTextAlignmentRight; + alertView.buttonsTextAlignment = NSTextAlignmentRight; + alertView.cancelButtonTextAlignment = NSTextAlignmentRight; + alertView.separatorsColor = nil; + [alertView showAnimated:YES completionHandler:nil]; + } + else if (indexPath.row == 7) + { + LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Button"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:nil + cancelHandler:nil + destructiveHandler:nil]; + + alertView.coverColor = [UIColor colorWithWhite:1.f alpha:0.9]; + alertView.layerShadowColor = [UIColor colorWithWhite:0.f alpha:0.3]; + alertView.layerShadowRadius = 4.f; + alertView.layerCornerRadius = 0.f; + alertView.layerBorderWidth = 2.f; + alertView.layerBorderColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + alertView.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.7]; + alertView.width = MIN(self.view.bounds.size.width, self.view.bounds.size.height); + alertView.titleTextAlignment = NSTextAlignmentLeft; + alertView.messageTextAlignment = NSTextAlignmentLeft; + alertView.destructiveButtonTextAlignment = NSTextAlignmentRight; + alertView.buttonsTextAlignment = NSTextAlignmentRight; + alertView.cancelButtonTextAlignment = NSTextAlignmentRight; + alertView.separatorsColor = nil; + alertView.destructiveButtonTitleColor = [UIColor whiteColor]; + alertView.buttonsTitleColor = [UIColor whiteColor]; + alertView.cancelButtonTitleColor = [UIColor whiteColor]; + alertView.destructiveButtonBackgroundColor = [UIColor colorWithRed:1.f green:0.f blue:0.f alpha:0.5]; + alertView.buttonsBackgroundColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:0.5]; + alertView.cancelButtonBackgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5]; + alertView.destructiveButtonBackgroundColorHighlighted = [UIColor colorWithRed:1.f green:0.f blue:0.f alpha:1.f]; + alertView.buttonsBackgroundColorHighlighted = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + alertView.cancelButtonBackgroundColorHighlighted = [UIColor colorWithWhite:0.5 alpha:1.f]; + [alertView showAnimated:YES completionHandler:nil]; + } + + [tableView deselectRowAtIndexPath:indexPath animated:YES]; +} + +@end diff --git a/Demo/Podfile.lock b/Demo/Podfile.lock index 5294841..2bd2a8a 100644 --- a/Demo/Podfile.lock +++ b/Demo/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - LGAlertView (1.1.1) + - LGAlertView (2.0.0) DEPENDENCIES: - LGAlertView (from `../`) @@ -9,6 +9,6 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - LGAlertView: 6d09e9aef4878d78c5f182ac196f1ea829c9ff61 + LGAlertView: 859226b0f4bf097819e04b9ab309277d17aae324 COCOAPODS: 0.39.0 diff --git a/LGAlertView.podspec b/LGAlertView.podspec index f2cb0da..aa2c678 100644 --- a/LGAlertView.podspec +++ b/LGAlertView.podspec @@ -1,13 +1,15 @@ Pod::Spec.new do |s| s.name = 'LGAlertView' - s.version = '1.1.2' + s.version = '2.0.0' s.platform = :ios, '6.0' s.license = 'MIT' s.homepage = 'https://github.com/Friend-LGA/LGAlertView' s.author = { 'Grigory Lutkov' => 'Friend.LGA@gmail.com' } s.source = { :git => 'https://github.com/Friend-LGA/LGAlertView.git', :tag => s.version } - s.summary = 'Customizable implementation of UIAlertView' + s.summary = 'Customizable implementation of UIAlertViewController, UIAlertView and UIActionSheet. All in one.' + s.description = 'Customizable implementation of UIAlertViewController, UIAlertView and UIActionSheet. All in one. ' \ + 'You can customize every detail. Make AlertView of your dream! :)' s.requires_arc = true diff --git a/LGAlertView/LGAlertView.h b/LGAlertView/LGAlertView.h index f1885a0..5725271 100644 --- a/LGAlertView/LGAlertView.h +++ b/LGAlertView/LGAlertView.h @@ -55,19 +55,39 @@ static NSString *const kLGAlertViewDestructiveNotification = @"LGAlertViewDestru @interface LGAlertView : NSObject +typedef enum +{ + LGAlertViewStyleAlert = 0, + LGAlertViewStyleActionSheet = 1 +} +LGAlertViewStyle; + +typedef enum +{ + LGAlertViewWindowLevelAboveStatusBar = 0, + LGAlertViewWindowLevelBelowStatusBar = 1 +} +LGAlertViewWindowLevel; + @property (assign, nonatomic, getter=isShowing) BOOL showing; +/** Default is LGAlertViewWindowLevelAboveStatusBar */ +@property (assign, nonatomic) LGAlertViewWindowLevel windowLevel; /** Default is YES */ @property (assign, nonatomic, getter=isCancelOnTouch) BOOL cancelOnTouch; /** Set highlighted buttons background color to blue, and set highlighted destructive button background color to red. Default is YES */ @property (assign, nonatomic, getter=isColorful) BOOL colorful; +/** Set colors of buttons title and background, cancel button title and background, activity indicator and progress view */ @property (strong, nonatomic) UIColor *tintColor; @property (strong, nonatomic) UIColor *coverColor; @property (strong, nonatomic) UIColor *backgroundColor; @property (assign, nonatomic) CGFloat buttonsHeight; @property (assign, nonatomic) CGFloat textFieldsHeight; +/** Top and bottom offsets from borders of the screen */ @property (assign, nonatomic) CGFloat offsetVertical; +/** Offset between cancel button and main view when style is LGAlertViewStyleActionSheet. Default is 8.f */ +@property (assign, nonatomic) CGFloat cancelButtonOffset; @property (assign, nonatomic) CGFloat heightMax; @property (assign, nonatomic) CGFloat width; @@ -76,6 +96,8 @@ static NSString *const kLGAlertViewDestructiveNotification = @"LGAlertViewDestru @property (assign, nonatomic) CGFloat layerBorderWidth; @property (strong, nonatomic) UIColor *layerShadowColor; @property (assign, nonatomic) CGFloat layerShadowRadius; +@property (assign, nonatomic) CGFloat layerShadowOpacity; +@property (assign, nonatomic) CGSize layerShadowOffset; @property (strong, nonatomic) UIColor *titleTextColor; @property (assign, nonatomic) NSTextAlignment titleTextAlignment; @@ -87,33 +109,38 @@ static NSString *const kLGAlertViewDestructiveNotification = @"LGAlertViewDestru @property (strong, nonatomic) UIColor *buttonsTitleColor; @property (strong, nonatomic) UIColor *buttonsTitleColorHighlighted; +@property (strong, nonatomic) UIColor *buttonsTitleColorDisabled; @property (assign, nonatomic) NSTextAlignment buttonsTextAlignment; @property (strong, nonatomic) UIFont *buttonsFont; +@property (strong, nonatomic) UIColor *buttonsBackgroundColor; @property (strong, nonatomic) UIColor *buttonsBackgroundColorHighlighted; +@property (strong, nonatomic) UIColor *buttonsBackgroundColorDisabled; @property (assign, nonatomic) NSUInteger buttonsNumberOfLines; @property (assign, nonatomic) NSLineBreakMode buttonsLineBreakMode; -@property (assign, nonatomic) BOOL buttonsAdjustsFontSizeToFitWidth; @property (assign, nonatomic) CGFloat buttonsMinimumScaleFactor; +@property (assign, nonatomic, getter=isButtonsAdjustsFontSizeToFitWidth) BOOL buttonsAdjustsFontSizeToFitWidth; @property (strong, nonatomic) UIColor *cancelButtonTitleColor; @property (strong, nonatomic) UIColor *cancelButtonTitleColorHighlighted; @property (assign, nonatomic) NSTextAlignment cancelButtonTextAlignment; @property (strong, nonatomic) UIFont *cancelButtonFont; +@property (strong, nonatomic) UIColor *cancelButtonBackgroundColor; @property (strong, nonatomic) UIColor *cancelButtonBackgroundColorHighlighted; @property (assign, nonatomic) NSUInteger cancelButtonNumberOfLines; @property (assign, nonatomic) NSLineBreakMode cancelButtonLineBreakMode; -@property (assign, nonatomic) BOOL cancelButtonAdjustsFontSizeToFitWidth; @property (assign, nonatomic) CGFloat cancelButtonMinimumScaleFactor; +@property (assign, nonatomic, getter=isCancelButtonAdjustsFontSizeToFitWidth) BOOL cancelButtonAdjustsFontSizeToFitWidth; @property (strong, nonatomic) UIColor *destructiveButtonTitleColor; @property (strong, nonatomic) UIColor *destructiveButtonTitleColorHighlighted; @property (assign, nonatomic) NSTextAlignment destructiveButtonTextAlignment; @property (strong, nonatomic) UIFont *destructiveButtonFont; +@property (strong, nonatomic) UIColor *destructiveButtonBackgroundColor; @property (strong, nonatomic) UIColor *destructiveButtonBackgroundColorHighlighted; @property (assign, nonatomic) NSUInteger destructiveButtonNumberOfLines; @property (assign, nonatomic) NSLineBreakMode destructiveButtonLineBreakMode; -@property (assign, nonatomic) BOOL destructiveButtonAdjustsFontSizeToFitWidth; @property (assign, nonatomic) CGFloat destructiveButtonMinimumScaleFactor; +@property (assign, nonatomic, getter=isDestructiveButtonAdjustsFontSizeToFitWidth) BOOL destructiveButtonAdjustsFontSizeToFitWidth; @property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; @property (strong, nonatomic) UIColor *activityIndicatorViewColor; @@ -132,6 +159,7 @@ static NSString *const kLGAlertViewDestructiveNotification = @"LGAlertViewDestru @property (strong, nonatomic) UIColor *separatorsColor; @property (assign, nonatomic) UIScrollViewIndicatorStyle indicatorStyle; +@property (assign, nonatomic, getter=isShowsVerticalScrollIndicator) BOOL showsVerticalScrollIndicator; @property (strong, nonatomic, readonly) NSMutableArray *textFieldsArray; @@ -155,79 +183,86 @@ static NSString *const kLGAlertViewDestructiveNotification = @"LGAlertViewDestru - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; -/** View can not be subclass of UIScrollView */ -- (instancetype)initWithViewStyleWithTitle:(NSString *)title +- (instancetype)initWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle; + +- (instancetype)initWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle; + +- (instancetype)initWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle; + +- (instancetype)initWithTextFieldsAndTitle:(NSString *)title message:(NSString *)message - view:(UIView *)view + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; -- (instancetype)initWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle; - -- (instancetype)initWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle; - -- (instancetype)initWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle; - + (instancetype)alertViewWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; -/** View can not be subclass of UIScrollView */ -+ (instancetype)alertViewWithViewStyleWithTitle:(NSString *)title ++ (instancetype)alertViewWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle; + ++ (instancetype)alertViewWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle; + ++ (instancetype)alertViewWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle; + ++ (instancetype)alertViewWithTextFieldsAndTitle:(NSString *)title message:(NSString *)message - view:(UIView *)view + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; -+ (instancetype)alertViewWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle; - -+ (instancetype)alertViewWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle; - -+ (instancetype)alertViewWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle; - #pragma mark - /** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle @@ -235,13 +270,46 @@ static NSString *const kLGAlertViewDestructiveNotification = @"LGAlertViewDestru cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; -/** - View can not be subclass of UIScrollView. - Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks. - */ -- (instancetype)initWithViewStyleWithTitle:(NSString *)title +/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ +- (instancetype)initWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; + +/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ +- (instancetype)initWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; + +/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ +- (instancetype)initWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; + +/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ +- (instancetype)initWithTextFieldsAndTitle:(NSString *)title message:(NSString *)message - view:(UIView *)view + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle @@ -249,42 +317,10 @@ static NSString *const kLGAlertViewDestructiveNotification = @"LGAlertViewDestru cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; -/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ -- (instancetype)initWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; - -/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ -- (instancetype)initWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; - -/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ -- (instancetype)initWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; - /** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ + (instancetype)alertViewWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle @@ -292,13 +328,46 @@ static NSString *const kLGAlertViewDestructiveNotification = @"LGAlertViewDestru cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; -/** - View can not be subclass of UIScrollView. - Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks. - */ -+ (instancetype)alertViewWithViewStyleWithTitle:(NSString *)title +/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ ++ (instancetype)alertViewWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; + +/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ ++ (instancetype)alertViewWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; + +/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ ++ (instancetype)alertViewWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; + +/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ ++ (instancetype)alertViewWithTextFieldsAndTitle:(NSString *)title message:(NSString *)message - view:(UIView *)view + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle @@ -306,121 +375,96 @@ static NSString *const kLGAlertViewDestructiveNotification = @"LGAlertViewDestru cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; -/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ -+ (instancetype)alertViewWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; - -/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ -+ (instancetype)alertViewWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; - -/** Do not forget about weak referens to self for actionHandler, cancelHandler and destructiveHandler blocks */ -+ (instancetype)alertViewWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler; - #pragma mark - - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle delegate:(id)delegate; /** View can not be subclass of UIScrollView */ -- (instancetype)initWithViewStyleWithTitle:(NSString *)title +- (instancetype)initWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate; + +- (instancetype)initWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate; + +- (instancetype)initWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate; + +- (instancetype)initWithTextFieldsAndTitle:(NSString *)title message:(NSString *)message - view:(UIView *)view + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle delegate:(id)delegate; -- (instancetype)initWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate; - -- (instancetype)initWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate; - -- (instancetype)initWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate; - + (instancetype)alertViewWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle delegate:(id)delegate; /** View can not be subclass of UIScrollView */ -+ (instancetype)alertViewWithViewStyleWithTitle:(NSString *)title ++ (instancetype)alertViewWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate; + ++ (instancetype)alertViewWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate; + ++ (instancetype)alertViewWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate; + ++ (instancetype)alertViewWithTextFieldsAndTitle:(NSString *)title message:(NSString *)message - view:(UIView *)view + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle delegate:(id)delegate; -+ (instancetype)alertViewWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate; - -+ (instancetype)alertViewWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate; - -+ (instancetype)alertViewWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate; - #pragma mark - - (void)showAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; @@ -428,6 +472,11 @@ static NSString *const kLGAlertViewDestructiveNotification = @"LGAlertViewDestru - (void)setProgress:(float)progress progressLabelText:(NSString *)progressLabelText; +- (void)setButtonAtIndex:(NSUInteger)index enabled:(BOOL)enabled; +- (BOOL)isButtonEnabledAtIndex:(NSUInteger)index; + +- (void)layoutInvalidateWithSize:(CGSize)size; + #pragma mark - /** Unavailable, use +alertViewWithTitle... instead */ diff --git a/LGAlertView/LGAlertView.m b/LGAlertView/LGAlertView.m index 17a63e1..5ed5b6a 100644 --- a/LGAlertView/LGAlertView.m +++ b/LGAlertView/LGAlertView.m @@ -28,62 +28,63 @@ // #import "LGAlertView.h" +#import "LGAlertViewWindow.h" +#import "LGAlertViewController.h" #import "LGAlertViewCell.h" #import "LGAlertViewTextField.h" #import "LGAlertViewShared.h" +#import "UIWindow+LGAlertView.h" -#define kLGAlertViewSeparatorHeight ([UIScreen mainScreen].scale == 1.f || [UIDevice currentDevice].systemVersion.floatValue < 7.0 ? 1.f : 0.5) -#define kLGAlertViewOffsetVertical (_offsetVertical >= 0 ? _offsetVertical : 16.f) -#define kLGAlertViewWidth (320.f - 16*2) +#define kLGAlertViewStatusBarHeight ([UIApplication sharedApplication].isStatusBarHidden ? 0.f : 20.f) +#define kLGAlertViewSeparatorHeight ([UIScreen mainScreen].scale == 1.f || [UIDevice currentDevice].systemVersion.floatValue < 7.0 ? 1.f : 0.5) +#define kLGAlertViewOffsetVertical (_offsetVertical >= 0 ? _offsetVertical : 8.f) +#define kLGAlertViewOffsetHorizontal 8.f +#define kLGAlertViewButtonTitleMarginH 8.f +#define kLGAlertViewWidth (320.f - 20*2) +#define kLGAlertViewInnerMarginH (_style == LGAlertViewStyleAlert ? 16.f : 12.f) +#define kLGAlertViewIsCancelButtonSeparate (_style == LGAlertViewStyleActionSheet && _cancelButtonOffset > 0.f) +#define kLGAlertViewButtonWidthMin 64.f +#define kLGAlertViewWindowPrevious(index) (index > 0 && index < kLGAlertViewWindowsArray.count ? [kLGAlertViewWindowsArray objectAtIndex:(index-1)] : nil) +#define kLGAlertViewWindowNext(index) (kLGAlertViewWindowsArray.count > index+1 ? [kLGAlertViewWindowsArray objectAtIndex:(index+1)] : nil) -static CGFloat const kLGAlertViewInnerMarginH = 16.f; -static CGFloat const kLGAlertViewButtonTitleMarginH = 8.f; +static NSMutableArray *kLGAlertViewWindowsArray; -@interface UIWindow (LGAlertView) - -- (UIViewController *)currentViewController; - -@end - -@interface LGAlertViewViewController : UIViewController - -@property (strong, nonatomic) LGAlertView *alertView; - -@end +#pragma mark - Interface @interface LGAlertView () typedef enum { - LGAlertViewStyleNone = 0, - LGAlertViewStyleActivityIndicator = 1, - LGAlertViewStyleProgressView = 2, - LGAlertViewStyleTextFields = 3 + LGAlertViewTypeDefault = 0, + LGAlertViewTypeActivityIndicator = 1, + LGAlertViewTypeProgressView = 2, + LGAlertViewTypeTextFields = 3 } -LGAlertViewStyle; +LGAlertViewType; @property (assign, nonatomic, getter=isExists) BOOL exists; -@property (strong, nonatomic) UIWindow *window; -@property (strong, nonatomic) UIWindow *windowPrevious; -@property (strong, nonatomic) UIWindow *windowNotice; +@property (strong, nonatomic) LGAlertViewWindow *window; @property (strong, nonatomic) UIView *view; -@property (strong, nonatomic) LGAlertViewViewController *viewController; +@property (strong, nonatomic) LGAlertViewController *viewController; @property (strong, nonatomic) UIView *backgroundView; -@property (strong, nonatomic) UIView *styleView; +@property (strong, nonatomic) UIView *styleView; +@property (strong, nonatomic) UIView *styleCancelView; + @property (strong, nonatomic) UIScrollView *scrollView; @property (strong, nonatomic) UITableView *tableView; -@property (strong, nonatomic) NSString *title; -@property (strong, nonatomic) NSString *message; -@property (strong, nonatomic) UIView *innerView; -@property (strong, nonatomic) NSMutableArray *buttonTitles; -@property (strong, nonatomic) NSString *cancelButtonTitle; -@property (strong, nonatomic) NSString *destructiveButtonTitle; +@property (assign, nonatomic) LGAlertViewStyle style; +@property (strong, nonatomic) NSString *title; +@property (strong, nonatomic) NSString *message; +@property (strong, nonatomic) UIView *innerView; +@property (strong, nonatomic) NSMutableArray *buttonTitles; +@property (strong, nonatomic) NSString *cancelButtonTitle; +@property (strong, nonatomic) NSString *destructiveButtonTitle; @property (strong, nonatomic) UILabel *titleLabel; @property (strong, nonatomic) UILabel *messageLabel; @@ -91,11 +92,13 @@ @interface LGAlertView () = __IPHONE_6_0 - -#pragma mark iOS <= 7 - -- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration -{ - [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; - - CGSize size = self.view.frame.size; - - if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) - size = CGSizeMake(MIN(size.width, size.height), MAX(size.width, size.height)); - else - size = CGSizeMake(MAX(size.width, size.height), MIN(size.width, size.height)); - - [_alertView layoutInvalidateWithSize:size]; -} - -#endif - -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0 - -#pragma mark iOS >= 8 - -- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator -{ - [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; - - [coordinator animateAlongsideTransition:^(id context) - { - [_alertView layoutInvalidateWithSize:size]; - } - completion:nil]; -} - -#endif - -- (UIStatusBarStyle)preferredStatusBarStyle -{ - return [UIApplication sharedApplication].statusBarStyle; -} - -@end +#pragma mark - Implementation @implementation LGAlertView - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle @@ -228,6 +148,7 @@ - (instancetype)initWithTitle:(NSString *)title self = [super init]; if (self) { + _style = style; _title = title; _message = message; _buttonTitles = buttonTitles.mutableCopy; @@ -239,21 +160,18 @@ - (instancetype)initWithTitle:(NSString *)title return self; } -- (instancetype)initWithViewStyleWithTitle:(NSString *)title - message:(NSString *)message - view:(UIView *)view - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle +- (instancetype)initWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle { self = [super init]; if (self) { - if ([view isKindOfClass:[UIScrollView class]]) - NSLog(@"LGFilterView: WARNING !!! view can not be subclass of UIScrollView !!!"); - - // ----- - + _style = style; _title = title; _message = message; _innerView = view; @@ -266,38 +184,42 @@ - (instancetype)initWithViewStyleWithTitle:(NSString *)title return self; } -- (instancetype)initWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle +- (instancetype)initWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle { self = [super init]; if (self) { + _style = style; _title = title; _message = message; _buttonTitles = buttonTitles.mutableCopy; _cancelButtonTitle = cancelButtonTitle; _destructiveButtonTitle = destructiveButtonTitle; - _style = LGAlertViewStyleActivityIndicator; + _type = LGAlertViewTypeActivityIndicator; [self setupDefaults]; } return self; } -- (instancetype)initWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle +- (instancetype)initWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle { self = [super init]; if (self) { + _style = style; _title = title; _message = message; _buttonTitles = buttonTitles.mutableCopy; @@ -305,20 +227,20 @@ - (instancetype)initWithProgressViewStyleWithTitle:(NSString *)title _destructiveButtonTitle = destructiveButtonTitle; _progressLabelText = progressLabelText; - _style = LGAlertViewStyleProgressView; + _type = LGAlertViewTypeProgressView; [self setupDefaults]; } return self; } -- (instancetype)initWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle +- (instancetype)initWithTextFieldsAndTitle:(NSString *)title + message:(NSString *)message + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle { self = [super init]; if (self) @@ -329,7 +251,7 @@ - (instancetype)initWithTextFieldsStyleWithTitle:(NSString *)title _cancelButtonTitle = cancelButtonTitle; _destructiveButtonTitle = destructiveButtonTitle; - _style = LGAlertViewStyleTextFields; + _type = LGAlertViewTypeTextFields; _textFieldsArray = [NSMutableArray new]; _textFieldSeparatorsArray = [NSMutableArray new]; @@ -362,81 +284,90 @@ - (instancetype)initWithTextFieldsStyleWithTitle:(NSString *)title + (instancetype)alertViewWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle { return [[self alloc] initWithTitle:title message:message + style:style buttonTitles:buttonTitles cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle]; } -+ (instancetype)alertViewWithViewStyleWithTitle:(NSString *)title ++ (instancetype)alertViewWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle +{ + return [[self alloc] initWithViewAndTitle:title + message:message + style:style + view:view + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle]; +} + ++ (instancetype)alertViewWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle +{ + return [[self alloc] initWithActivityIndicatorAndTitle:title + message:message + style:style + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle]; +} + ++ (instancetype)alertViewWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle +{ + return [[self alloc] initWithProgressViewAndTitle:title + message:message + style:style + progressLabelText:progressLabelText + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle]; +} + ++ (instancetype)alertViewWithTextFieldsAndTitle:(NSString *)title message:(NSString *)message - view:(UIView *)view + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle { - return [[self alloc] initWithViewStyleWithTitle:title + return [[self alloc] initWithTextFieldsAndTitle:title message:message - view:view + numberOfTextFields:numberOfTextFields + textFieldsSetupHandler:textFieldsSetupHandler buttonTitles:buttonTitles cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle]; } -+ (instancetype)alertViewWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle -{ - return [[self alloc] initWithActivityIndicatorStyleWithTitle:title - message:message - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle]; -} - -+ (instancetype)alertViewWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle -{ - return [[self alloc] initWithProgressViewStyleWithTitle:title - message:message - progressLabelText:progressLabelText - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle]; -} - -+ (instancetype)alertViewWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void (^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle -{ - return [[self alloc] initWithTextFieldsStyleWithTitle:title - message:message - numberOfTextFields:numberOfTextFields - textFieldsSetupHandler:textFieldsSetupHandler - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle]; -} - #pragma mark - - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle @@ -446,6 +377,7 @@ - (instancetype)initWithTitle:(NSString *)title { self = [self initWithTitle:title message:message + style:style buttonTitles:buttonTitles cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle]; @@ -458,22 +390,24 @@ - (instancetype)initWithTitle:(NSString *)title return self; } -- (instancetype)initWithViewStyleWithTitle:(NSString *)title - message:(NSString *)message - view:(UIView *)view - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler -{ - self = [self initWithViewStyleWithTitle:title - message:message - view:view - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle]; +- (instancetype)initWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler +{ + self = [self initWithViewAndTitle:title + message:message + style:style + view:view + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle]; if (self) { _actionHandler = actionHandler; @@ -483,20 +417,22 @@ - (instancetype)initWithViewStyleWithTitle:(NSString *)title return self; } -- (instancetype)initWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler -{ - self = [self initWithActivityIndicatorStyleWithTitle:title - message:message - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle]; +- (instancetype)initWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler +{ + self = [self initWithActivityIndicatorAndTitle:title + message:message + style:style + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle]; if (self) { _actionHandler = actionHandler; @@ -506,22 +442,24 @@ - (instancetype)initWithActivityIndicatorStyleWithTitle:(NSString *)title return self; } -- (instancetype)initWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler -{ - self = [self initWithProgressViewStyleWithTitle:title - message:message - progressLabelText:progressLabelText - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle]; +- (instancetype)initWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler +{ + self = [self initWithProgressViewAndTitle:title + message:message + style:style + progressLabelText:progressLabelText + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle]; if (self) { _actionHandler = actionHandler; @@ -531,24 +469,24 @@ - (instancetype)initWithProgressViewStyleWithTitle:(NSString *)title return self; } -- (instancetype)initWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler -{ - self = [self initWithTextFieldsStyleWithTitle:title - message:message - numberOfTextFields:numberOfTextFields - textFieldsSetupHandler:textFieldsSetupHandler - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle]; +- (instancetype)initWithTextFieldsAndTitle:(NSString *)title + message:(NSString *)message + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler +{ + self = [self initWithTextFieldsAndTitle:title + message:message + numberOfTextFields:numberOfTextFields + textFieldsSetupHandler:textFieldsSetupHandler + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle]; if (self) { _actionHandler = actionHandler; @@ -560,6 +498,7 @@ - (instancetype)initWithTextFieldsStyleWithTitle:(NSString *)title + (instancetype)alertViewWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle @@ -569,6 +508,7 @@ + (instancetype)alertViewWithTitle:(NSString *)title { return [[self alloc] initWithTitle:title message:message + style:style buttonTitles:buttonTitles cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle @@ -577,9 +517,77 @@ + (instancetype)alertViewWithTitle:(NSString *)title destructiveHandler:destructiveHandler]; } -+ (instancetype)alertViewWithViewStyleWithTitle:(NSString *)title ++ (instancetype)alertViewWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler +{ + return [[self alloc] initWithViewAndTitle:title + message:message + style:style + view:view + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle + actionHandler:actionHandler + cancelHandler:cancelHandler + destructiveHandler:destructiveHandler]; +} + ++ (instancetype)alertViewWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler +{ + return [[self alloc] initWithActivityIndicatorAndTitle:title + message:message + style:style + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle + actionHandler:actionHandler + cancelHandler:cancelHandler + destructiveHandler:destructiveHandler]; +} + ++ (instancetype)alertViewWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler + cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler + destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler +{ + return [[self alloc] initWithProgressViewAndTitle:title + message:message + style:style + progressLabelText:progressLabelText + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle + actionHandler:actionHandler + cancelHandler:cancelHandler + destructiveHandler:destructiveHandler]; +} + ++ (instancetype)alertViewWithTextFieldsAndTitle:(NSString *)title message:(NSString *)message - view:(UIView *)view + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle @@ -587,84 +595,23 @@ + (instancetype)alertViewWithViewStyleWithTitle:(NSString *)title cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler { - return [[self alloc] initWithViewStyleWithTitle:title - message:message - view:view - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle - actionHandler:actionHandler - cancelHandler:cancelHandler - destructiveHandler:destructiveHandler]; -} - -+ (instancetype)alertViewWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler -{ - return [[self alloc] initWithActivityIndicatorStyleWithTitle:title - message:message - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle - actionHandler:actionHandler - cancelHandler:cancelHandler - destructiveHandler:destructiveHandler]; -} - -+ (instancetype)alertViewWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler -{ - return [[self alloc] initWithProgressViewStyleWithTitle:title - message:message - progressLabelText:progressLabelText - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle - actionHandler:actionHandler - cancelHandler:cancelHandler - destructiveHandler:destructiveHandler]; -} - -+ (instancetype)alertViewWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - actionHandler:(void(^)(LGAlertView *alertView, NSString *title, NSUInteger index))actionHandler - cancelHandler:(void(^)(LGAlertView *alertView, BOOL onButton))cancelHandler - destructiveHandler:(void(^)(LGAlertView *alertView))destructiveHandler -{ - return [[self alloc] alertViewWithTextFieldsStyleWithTitle:title - message:message - numberOfTextFields:numberOfTextFields - textFieldsSetupHandler:textFieldsSetupHandler - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle - actionHandler:actionHandler - cancelHandler:cancelHandler - destructiveHandler:destructiveHandler]; + return [[self alloc] alertViewWithTextFieldsAndTitle:title + message:message + numberOfTextFields:numberOfTextFields + textFieldsSetupHandler:textFieldsSetupHandler + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle + actionHandler:actionHandler + cancelHandler:cancelHandler + destructiveHandler:destructiveHandler]; } #pragma mark - - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle @@ -672,6 +619,7 @@ - (instancetype)initWithTitle:(NSString *)title { self = [self initWithTitle:title message:message + style:style buttonTitles:buttonTitles cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle]; @@ -682,20 +630,22 @@ - (instancetype)initWithTitle:(NSString *)title return self; } -- (instancetype)initWithViewStyleWithTitle:(NSString *)title - message:(NSString *)message - view:(UIView *)view - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate -{ - self = [self initWithViewStyleWithTitle:title - message:message - view:view - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle]; +- (instancetype)initWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate +{ + self = [self initWithViewAndTitle:title + message:message + style:style + view:view + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle]; if (self) { _delegate = delegate; @@ -703,18 +653,20 @@ - (instancetype)initWithViewStyleWithTitle:(NSString *)title return self; } -- (instancetype)initWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate -{ - self = [self initWithActivityIndicatorStyleWithTitle:title - message:message - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle]; +- (instancetype)initWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate +{ + self = [self initWithActivityIndicatorAndTitle:title + message:message + style:style + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle]; if (self) { _delegate = delegate; @@ -722,20 +674,22 @@ - (instancetype)initWithActivityIndicatorStyleWithTitle:(NSString *)title return self; } -- (instancetype)initWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate -{ - self = [self initWithProgressViewStyleWithTitle:title - message:message - progressLabelText:progressLabelText - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle]; +- (instancetype)initWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate +{ + self = [self initWithProgressViewAndTitle:title + message:message + style:style + progressLabelText:progressLabelText + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle]; if (self) { _delegate = delegate; @@ -743,22 +697,22 @@ - (instancetype)initWithProgressViewStyleWithTitle:(NSString *)title return self; } -- (instancetype)initWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate -{ - self = [self initWithTextFieldsStyleWithTitle:title - message:message - numberOfTextFields:numberOfTextFields - textFieldsSetupHandler:textFieldsSetupHandler - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle]; +- (instancetype)initWithTextFieldsAndTitle:(NSString *)title + message:(NSString *)message + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate +{ + self = [self initWithTextFieldsAndTitle:title + message:message + numberOfTextFields:numberOfTextFields + textFieldsSetupHandler:textFieldsSetupHandler + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle]; if (self) { _delegate = delegate; @@ -768,6 +722,7 @@ - (instancetype)initWithTextFieldsStyleWithTitle:(NSString *)title + (instancetype)alertViewWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle @@ -775,94 +730,111 @@ + (instancetype)alertViewWithTitle:(NSString *)title { return [[self alloc] initWithTitle:title message:message + style:style buttonTitles:buttonTitles cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle delegate:delegate]; } -+ (instancetype)alertViewWithViewStyleWithTitle:(NSString *)title ++ (instancetype)alertViewWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate +{ + return [[self alloc] initWithViewAndTitle:title + message:message + style:style + view:view + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle + delegate:delegate]; +} + ++ (instancetype)alertViewWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate +{ + return [[self alloc] initWithActivityIndicatorAndTitle:title + message:message + style:style + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle + delegate:delegate]; +} + ++ (instancetype)alertViewWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle + delegate:(id)delegate +{ + return [[self alloc] initWithProgressViewAndTitle:title + message:message + style:style + progressLabelText:progressLabelText + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle + delegate:delegate]; +} + ++ (instancetype)alertViewWithTextFieldsAndTitle:(NSString *)title message:(NSString *)message - view:(UIView *)view + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle delegate:(id)delegate { - return [[self alloc] initWithViewStyleWithTitle:title - message:message - view:view - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle - delegate:delegate]; -} - -+ (instancetype)alertViewWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate -{ - return [[self alloc] initWithActivityIndicatorStyleWithTitle:title - message:message - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle - delegate:delegate]; -} - -+ (instancetype)alertViewWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate -{ - return [[self alloc] initWithProgressViewStyleWithTitle:title - message:message - progressLabelText:progressLabelText - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle - delegate:delegate]; -} - -+ (instancetype)alertViewWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle - delegate:(id)delegate -{ - return [[self alloc] alertViewWithTextFieldsStyleWithTitle:title - message:message - numberOfTextFields:numberOfTextFields - textFieldsSetupHandler:textFieldsSetupHandler - buttonTitles:buttonTitles - cancelButtonTitle:cancelButtonTitle - destructiveButtonTitle:destructiveButtonTitle - delegate:delegate]; + return [[self alloc] alertViewWithTextFieldsAndTitle:title + message:message + numberOfTextFields:numberOfTextFields + textFieldsSetupHandler:textFieldsSetupHandler + buttonTitles:buttonTitles + cancelButtonTitle:cancelButtonTitle + destructiveButtonTitle:destructiveButtonTitle + delegate:delegate]; } #pragma mark - - (void)setupDefaults { - _cancelOnTouch = YES; + if (!kLGAlertViewWindowsArray) + kLGAlertViewWindowsArray = [NSMutableArray new]; + + // ----- + + _cancelOnTouch = !(_type == LGAlertViewTypeActivityIndicator || _type == LGAlertViewTypeProgressView || _type == LGAlertViewTypeTextFields); + + _disabledButtonIndex = -1; + + // ----- self.tintColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; _coverColor = [UIColor colorWithWhite:0.f alpha:0.5]; _backgroundColor = [UIColor whiteColor]; - _buttonsHeight = 44.f; + _buttonsHeight = (([UIDevice currentDevice].systemVersion.floatValue < 9.0 || _style == LGAlertViewStyleAlert) ? 44.f : 56.f); _textFieldsHeight = 44.f; _offsetVertical = -1; + _cancelButtonOffset = kLGAlertViewOffsetHorizontal; _heightMax = -1.f; _width = -1.f; @@ -871,24 +843,47 @@ - (void)setupDefaults _layerBorderWidth = 0.f; _layerShadowColor = nil; _layerShadowRadius = 0.f; + _layerShadowOpacity = 1.f; + _layerShadowOffset = CGSizeZero; - _titleTextColor = [UIColor blackColor]; - _titleTextAlignment = NSTextAlignmentCenter; - _titleFont = [UIFont boldSystemFontOfSize:18.f]; + if (_style == LGAlertViewStyleAlert) + { + _titleTextColor = [UIColor blackColor]; + _titleTextAlignment = NSTextAlignmentCenter; + _titleFont = [UIFont boldSystemFontOfSize:18.f]; + } + else + { + _titleTextColor = [UIColor grayColor]; + _titleTextAlignment = NSTextAlignmentCenter; + _titleFont = [UIFont boldSystemFontOfSize:14.f]; + } - _messageTextColor = [UIColor blackColor]; - _messageTextAlignment = NSTextAlignmentCenter; - _messageFont = [UIFont systemFontOfSize:14.f]; + if (_style == LGAlertViewStyleAlert) + { + _messageTextColor = [UIColor blackColor]; + _messageTextAlignment = NSTextAlignmentCenter; + _messageFont = [UIFont systemFontOfSize:14.f]; + } + else + { + _messageTextColor = [UIColor grayColor]; + _messageTextAlignment = NSTextAlignmentCenter; + _messageFont = [UIFont systemFontOfSize:14.f]; + } _buttonsTitleColor = _tintColor; _buttonsTitleColorHighlighted = [UIColor whiteColor]; + _buttonsTitleColorDisabled = [UIColor grayColor]; _buttonsTextAlignment = NSTextAlignmentCenter; _buttonsFont = [UIFont systemFontOfSize:18.f]; _buttonsNumberOfLines = 1; _buttonsLineBreakMode = NSLineBreakByTruncatingMiddle; _buttonsAdjustsFontSizeToFitWidth = YES; _buttonsMinimumScaleFactor = 14.f/18.f; + _buttonsBackgroundColor = nil; _buttonsBackgroundColorHighlighted = _tintColor; + _buttonsBackgroundColorDisabled = _buttonsBackgroundColor; _cancelButtonTitleColor = _tintColor; _cancelButtonTitleColorHighlighted = [UIColor whiteColor]; @@ -898,6 +893,7 @@ - (void)setupDefaults _cancelButtonLineBreakMode = NSLineBreakByTruncatingMiddle; _cancelButtonAdjustsFontSizeToFitWidth = YES; _cancelButtonMinimumScaleFactor = 14.f/18.f; + _cancelButtonBackgroundColor = nil; _cancelButtonBackgroundColorHighlighted = _tintColor; _destructiveButtonTitleColor = [UIColor redColor]; @@ -908,6 +904,7 @@ - (void)setupDefaults _destructiveButtonLineBreakMode = NSLineBreakByTruncatingMiddle; _destructiveButtonAdjustsFontSizeToFitWidth = YES; _destructiveButtonMinimumScaleFactor = 14.f/18.f; + _destructiveButtonBackgroundColor = nil; _destructiveButtonBackgroundColorHighlighted = [UIColor redColor]; _activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; @@ -927,6 +924,7 @@ - (void)setupDefaults _separatorsColor = [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1.f]; _indicatorStyle = UIScrollViewIndicatorStyleBlack; + _showsVerticalScrollIndicator = NO; // ----- @@ -948,11 +946,10 @@ - (void)setupDefaults // ----- - _viewController = [[LGAlertViewViewController alloc] initWithAlertView:self]; + _viewController = [[LGAlertViewController alloc] initWithAlertView:self view:_view]; - _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; + _window = [[LGAlertViewWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; _window.hidden = YES; - _window.windowLevel = UIWindowLevelStatusBar+1; _window.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; _window.opaque = NO; _window.backgroundColor = [UIColor clearColor]; @@ -996,36 +993,41 @@ - (void)removeObservers - (void)windowVisibleChanged:(NSNotification *)notification { + NSUInteger windowIndex = [kLGAlertViewWindowsArray indexOfObject:_window]; + //NSLog(@"windowVisibleChanged: %@", notification); - UIWindow *window = notification.object; + UIWindow *windowNotif = notification.object; //NSLog(@"%@", NSStringFromClass([window class])); - if ([NSStringFromClass([window class]) isEqualToString:@"UITextEffectsWindow"] || - [NSStringFromClass([window class]) isEqualToString:@"UIRemoteKeyboardWindow"] || - [window isEqual:_window]) return; + if ([NSStringFromClass([windowNotif class]) isEqualToString:@"UITextEffectsWindow"] || + [NSStringFromClass([windowNotif class]) isEqualToString:@"UIRemoteKeyboardWindow"] || + [NSStringFromClass([windowNotif class]) isEqualToString:@"LGAlertViewWindow"] || + [windowNotif isEqual:_window]) return; if (notification.name == UIWindowDidBecomeVisibleNotification) { - if ([window isEqual:_windowPrevious]) + if ([windowNotif isEqual:kLGAlertViewWindowPrevious(windowIndex)]) { - window.hidden = YES; + windowNotif.hidden = YES; + + [_window makeKeyAndVisible]; } - else if (!_windowNotice) + else if (!kLGAlertViewWindowNext(windowIndex)) { - _windowNotice = window; - _window.hidden = YES; + + [kLGAlertViewWindowsArray addObject:windowNotif]; } } else if (notification.name == UIWindowDidBecomeHiddenNotification) { - if ([window isEqual:_windowNotice]) + if ([windowNotif isEqual:kLGAlertViewWindowNext(windowIndex)] && [windowNotif isEqual:kLGAlertViewWindowsArray.lastObject]) { - _windowNotice = nil; - [_window makeKeyAndVisible]; + + [kLGAlertViewWindowsArray removeLastObject]; } } } @@ -1089,25 +1091,37 @@ - (void)setColorful:(BOOL)colorful if (_colorful) { - _buttonsTitleColorHighlighted = [UIColor whiteColor]; - _buttonsBackgroundColorHighlighted = _tintColor; - - _cancelButtonTitleColorHighlighted = [UIColor whiteColor]; - _cancelButtonBackgroundColorHighlighted = _tintColor; - - _destructiveButtonTitleColorHighlighted = [UIColor whiteColor]; - _destructiveButtonBackgroundColorHighlighted = [UIColor redColor]; + if (!self.isUserButtonsTitleColorHighlighted) + _buttonsTitleColorHighlighted = [UIColor whiteColor]; + if (!self.isUserButtonsBackgroundColorHighlighted) + _buttonsBackgroundColorHighlighted = _tintColor; + + if (!self.isUserCancelButtonTitleColorHighlighted) + _cancelButtonTitleColorHighlighted = [UIColor whiteColor]; + if (!self.isUserCancelButtonBackgroundColorHighlighted) + _cancelButtonBackgroundColorHighlighted = _tintColor; + + if (!self.isUserDestructiveButtonTitleColorHighlighted) + _destructiveButtonTitleColorHighlighted = [UIColor whiteColor]; + if (!self.isUserDestructiveButtonBackgroundColorHighlighted) + _destructiveButtonBackgroundColorHighlighted = [UIColor redColor]; } else { - _buttonsTitleColorHighlighted = _buttonsTitleColor; - _buttonsBackgroundColorHighlighted = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.f]; - - _cancelButtonTitleColorHighlighted = _cancelButtonTitleColor; - _cancelButtonBackgroundColorHighlighted = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.f]; - - _destructiveButtonTitleColorHighlighted = _destructiveButtonTitleColor; - _destructiveButtonBackgroundColorHighlighted = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.f]; + if (!self.isUserButtonsTitleColorHighlighted) + _buttonsTitleColorHighlighted = _buttonsTitleColor; + if (!self.isUserButtonsBackgroundColorHighlighted) + _buttonsBackgroundColorHighlighted = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.f]; + + if (!self.isUserCancelButtonTitleColorHighlighted) + _cancelButtonTitleColorHighlighted = _cancelButtonTitleColor; + if (!self.isUserCancelButtonBackgroundColorHighlighted) + _cancelButtonBackgroundColorHighlighted = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.f]; + + if (!self.isUserDestructiveButtonTitleColorHighlighted) + _destructiveButtonTitleColorHighlighted = _destructiveButtonTitleColor; + if (!self.isUserDestructiveButtonBackgroundColorHighlighted) + _destructiveButtonBackgroundColorHighlighted = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.f]; } } @@ -1115,20 +1129,28 @@ - (void)setTintColor:(UIColor *)tintColor { _tintColor = tintColor; - _buttonsBackgroundColorHighlighted = _tintColor; - _cancelButtonBackgroundColorHighlighted = _tintColor; - - _buttonsTitleColor = _tintColor; - _cancelButtonTitleColor = _tintColor; + if (!self.isUserButtonsTitleColor) + _buttonsTitleColor = _tintColor; + if (!self.isUserCancelButtonTitleColor) + _cancelButtonTitleColor = _tintColor; if (!self.isColorful) { - _buttonsTitleColorHighlighted = _tintColor; - _cancelButtonTitleColorHighlighted = _tintColor; + if (!self.isUserButtonsTitleColorHighlighted) + _buttonsTitleColorHighlighted = _tintColor; + if (!self.isUserCancelButtonTitleColorHighlighted) + _cancelButtonTitleColorHighlighted = _tintColor; } - _activityIndicatorViewColor = _tintColor; - _progressViewProgressTintColor = _tintColor; + if (!self.isUserButtonsBackgroundColorHighlighted) + _buttonsBackgroundColorHighlighted = _tintColor; + if (!self.isUserCancelButtonBackgroundColorHighlighted) + _cancelButtonBackgroundColorHighlighted = _tintColor; + + if (!self.isUserActivityIndicatorViewColor) + _activityIndicatorViewColor = _tintColor; + if (!self.isUserProgressViewProgressTintColor) + _progressViewProgressTintColor = _tintColor; } - (void)setButtonsHeight:(CGFloat)buttonsHeight @@ -1145,9 +1167,81 @@ - (void)setTextFieldsHeight:(CGFloat)textFieldsHeight _textFieldsHeight = textFieldsHeight; } +- (void)setButtonsTitleColor:(UIColor *)buttonsTitleColor +{ + _buttonsTitleColor = buttonsTitleColor; + + _userButtonsTitleColor = YES; +} + +- (void)setButtonsTitleColorHighlighted:(UIColor *)buttonsTitleColorHighlighted +{ + _buttonsTitleColorHighlighted = buttonsTitleColorHighlighted; + + _userButtonsTitleColorHighlighted = YES; +} + +- (void)setButtonsBackgroundColorHighlighted:(UIColor *)buttonsBackgroundColorHighlighted +{ + _buttonsBackgroundColorHighlighted = buttonsBackgroundColorHighlighted; + + _userButtonsBackgroundColorHighlighted = YES; +} + +- (void)setCancelButtonTitleColor:(UIColor *)cancelButtonTitleColor +{ + _cancelButtonTitleColor = cancelButtonTitleColor; + + _userCancelButtonTitleColor = YES; +} + +- (void)setCancelButtonTitleColorHighlighted:(UIColor *)cancelButtonTitleColorHighlighted +{ + _cancelButtonTitleColorHighlighted = cancelButtonTitleColorHighlighted; + + _userCancelButtonTitleColorHighlighted = YES; +} + +- (void)setCancelButtonBackgroundColorHighlighted:(UIColor *)cancelButtonBackgroundColorHighlighted +{ + _cancelButtonBackgroundColorHighlighted = cancelButtonBackgroundColorHighlighted; + + _userCancelButtonBackgroundColorHighlighted = YES; +} + +- (void)setDestructiveButtonTitleColorHighlighted:(UIColor *)destructiveButtonTitleColorHighlighted +{ + _destructiveButtonTitleColorHighlighted = destructiveButtonTitleColorHighlighted; + + _userDestructiveButtonTitleColorHighlighted = YES; +} + +- (void)setDestructiveButtonBackgroundColorHighlighted:(UIColor *)destructiveButtonBackgroundColorHighlighted +{ + _destructiveButtonBackgroundColorHighlighted = destructiveButtonBackgroundColorHighlighted; + + _userDestructiveButtonBackgroundColorHighlighted = YES; +} + +- (void)setActivityIndicatorViewColor:(UIColor *)activityIndicatorViewColor +{ + _activityIndicatorViewColor = activityIndicatorViewColor; + + _userActivityIndicatorViewColor = YES; +} + +- (void)setProgressViewProgressTintColor:(UIColor *)progressViewProgressTintColor +{ + _progressViewProgressTintColor = progressViewProgressTintColor; + + _userProgressViewProgressTintColor = YES; +} + +#pragma mark - + - (void)setProgress:(float)progress progressLabelText:(NSString *)progressLabelText { - if (_style == LGAlertViewStyleProgressView) + if (_type == LGAlertViewTypeProgressView) { [_progressView setProgress:progress animated:YES]; @@ -1159,12 +1253,65 @@ - (float)progress { float progress = 0.f; - if (_style == LGAlertViewStyleProgressView) + if (_type == LGAlertViewTypeProgressView) progress = _progressView.progress; return progress; } +- (void)setButtonAtIndex:(NSUInteger)index enabled:(BOOL)enabled +{ + if (_buttonTitles.count <= index) return; + + if (_tableView) + { + if (enabled) + _disabledButtonIndex = -1; + else + { + _disabledButtonIndex = index; + if (_destructiveButtonTitle.length) + _disabledButtonIndex++; + } + + LGAlertViewCell *cell = (LGAlertViewCell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:_disabledButtonIndex inSection:0]]; + cell.enabled = enabled; + } + else + { + if (enabled) + _disabledButtonIndex = -1; + else + _disabledButtonIndex = index; + + switch (index) + { + case 0: + _firstButton.enabled = enabled; + break; + case 1: + _secondButton.enabled = enabled; + break; + case 2: + _thirdButton.enabled = enabled; + break; + default: + break; + } + } +} + +- (BOOL)isButtonEnabledAtIndex:(NSUInteger)index +{ + if (_disabledButtonIndex == -1) return YES; + else + { + if (_tableView) index++; + + return !(index == _disabledButtonIndex); + } +} + #pragma mark - Table View Data Source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView @@ -1187,6 +1334,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { cell.titleColor = _destructiveButtonTitleColor; cell.titleColorHighlighted = _destructiveButtonTitleColorHighlighted; + cell.backgroundColorNormal = _destructiveButtonBackgroundColor; cell.backgroundColorHighlighted = _destructiveButtonBackgroundColorHighlighted; cell.separatorVisible = (indexPath.row != _buttonTitles.count-1); cell.separatorColor_ = _separatorsColor; @@ -1197,10 +1345,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.adjustsFontSizeToFitWidth = _destructiveButtonAdjustsFontSizeToFitWidth; cell.minimumScaleFactor = _destructiveButtonMinimumScaleFactor; } - else if (_cancelButtonTitle.length && indexPath.row == _buttonTitles.count-1) + else if (_cancelButtonTitle.length && !kLGAlertViewIsCancelButtonSeparate && indexPath.row == _buttonTitles.count-1) { cell.titleColor = _cancelButtonTitleColor; cell.titleColorHighlighted = _cancelButtonTitleColorHighlighted; + cell.backgroundColorNormal = _cancelButtonBackgroundColor; cell.backgroundColorHighlighted = _cancelButtonBackgroundColorHighlighted; cell.separatorVisible = NO; cell.separatorColor_ = _separatorsColor; @@ -1215,7 +1364,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { cell.titleColor = _buttonsTitleColor; cell.titleColorHighlighted = _buttonsTitleColorHighlighted; + cell.titleColorDisabled = _buttonsTitleColorDisabled; + cell.backgroundColorNormal = _buttonsBackgroundColor; cell.backgroundColorHighlighted = _buttonsBackgroundColorHighlighted; + cell.backgroundColorDisabled = _buttonsBackgroundColorDisabled; cell.separatorVisible = (indexPath.row != _buttonTitles.count-1); cell.separatorColor_ = _separatorsColor; cell.textAlignment = _buttonsTextAlignment; @@ -1224,6 +1376,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.lineBreakMode = _buttonsLineBreakMode; cell.adjustsFontSizeToFitWidth = _buttonsAdjustsFontSizeToFitWidth; cell.minimumScaleFactor = _buttonsMinimumScaleFactor; + cell.enabled = !(indexPath.row == _disabledButtonIndex); } return cell; @@ -1254,7 +1407,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa return size.height; } - else if (_cancelButtonTitle.length && indexPath.row == _buttonTitles.count-1 && _cancelButtonNumberOfLines != 1) + else if (_cancelButtonTitle.length && !kLGAlertViewIsCancelButtonSeparate && indexPath.row == _buttonTitles.count-1 && _cancelButtonNumberOfLines != 1) { NSString *title = _buttonTitles[indexPath.row]; @@ -1311,8 +1464,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath } else { - [self dismissAnimated:YES completionHandler:nil]; - NSUInteger index = indexPath.row; if (_destructiveButtonTitle.length) index--; @@ -1320,15 +1471,19 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath // ----- + if (_actionHandler) _actionHandler(self, title, index); + + if (_delegate && [_delegate respondsToSelector:@selector(alertView:buttonPressedWithTitle:index:)]) + [_delegate alertView:self buttonPressedWithTitle:title index:index]; + [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewActionNotification object:self userInfo:@{@"title" : title, @"index" : [NSNumber numberWithInteger:index]}]; - if (_actionHandler) _actionHandler(self, title, index); + // ----- - if (_delegate && [_delegate respondsToSelector:@selector(alertView:buttonPressedWithTitle:index:)]) - [_delegate alertView:self buttonPressedWithTitle:title index:index]; + [self dismissAnimated:YES completionHandler:nil]; } } @@ -1338,6 +1493,9 @@ - (void)showAnimated:(BOOL)animated completionHandler:(void(^)())completionHandl { if (self.isShowing) return; + _window.windowLevel = UIWindowLevelStatusBar + (_windowLevel == LGAlertViewWindowLevelAboveStatusBar ? 1 : -1); + _window.userInteractionEnabled = NO; + CGSize size = _viewController.view.frame.size; if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) @@ -1362,22 +1520,32 @@ - (void)showAnimated:(BOOL)animated completionHandler:(void(^)())completionHandl // ----- UIWindow *windowApp = [UIApplication sharedApplication].delegate.window; - _windowPrevious = [UIApplication sharedApplication].keyWindow; + UIWindow *windowKey = [UIApplication sharedApplication].keyWindow; + + if (!kLGAlertViewWindowsArray.count) + [kLGAlertViewWindowsArray addObject:windowApp]; - if (![windowApp isEqual:_windowPrevious]) - _windowPrevious.hidden = YES; + if (![windowKey isEqual:windowApp]) + if (![kLGAlertViewWindowsArray containsObject:windowKey]) + [kLGAlertViewWindowsArray addObject:windowKey]; + + if (![kLGAlertViewWindowsArray containsObject:_window]) + [kLGAlertViewWindowsArray addObject:_window]; + + if (![windowKey isEqual:windowApp]) + windowKey.hidden = YES; [_window makeKeyAndVisible]; // ----- - [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewWillShowNotification object:self userInfo:nil]; - if (_willShowHandler) _willShowHandler(self); if (_delegate && [_delegate respondsToSelector:@selector(alertViewWillShow:)]) [_delegate alertViewWillShow:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewWillShowNotification object:self userInfo:nil]; + // ----- if (animated) @@ -1407,27 +1575,54 @@ - (void)showAnimations { _backgroundView.alpha = 1.f; - _scrollView.transform = CGAffineTransformIdentity; - _scrollView.alpha = 1.f; + if (_style == LGAlertViewStyleAlert) + { + _scrollView.transform = CGAffineTransformIdentity; + _scrollView.alpha = 1.f; + + _styleView.transform = CGAffineTransformIdentity; + _styleView.alpha = 1.f; + } + else + { + _scrollView.center = _scrollViewCenterShowed; + + _styleView.center = _scrollViewCenterShowed; + } - _styleView.transform = CGAffineTransformIdentity; - _styleView.alpha = 1.f; + if (kLGAlertViewIsCancelButtonSeparate && _cancelButton) + { + _cancelButton.center = _cancelButtonCenterShowed; + + _styleCancelView.center = _cancelButtonCenterShowed; + } } - (void)showComplete { - [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewDidShowNotification object:self userInfo:nil]; + if (_type == LGAlertViewTypeTextFields && _textFieldsArray.count) + [_textFieldsArray[0] becomeFirstResponder]; + + // ----- if (_didShowHandler) _didShowHandler(self); if (_delegate && [_delegate respondsToSelector:@selector(alertViewDidShow:)]) [_delegate alertViewDidShow:self]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewDidShowNotification object:self userInfo:nil]; + + // ----- + + _window.userInteractionEnabled = YES; } -- (void)dismissAnimated:(BOOL)animated completionHandler:(void (^)())completionHandler +- (void)dismissAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler { if (!self.isShowing) return; + _window.userInteractionEnabled = NO; + _showing = NO; [self removeObservers]; @@ -1436,13 +1631,13 @@ - (void)dismissAnimated:(BOOL)animated completionHandler:(void (^)())completionH // ----- - [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewWillDismissNotification object:self userInfo:nil]; - if (_willDismissHandler) _willDismissHandler(self); if (_delegate && [_delegate respondsToSelector:@selector(alertViewWillDismiss:)]) [_delegate alertViewWillDismiss:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewWillDismissNotification object:self userInfo:nil]; + // ----- if (animated) @@ -1472,42 +1667,64 @@ - (void)dismissAnimations { _backgroundView.alpha = 0.f; - _scrollView.transform = CGAffineTransformMakeScale(0.95, 0.95); - _scrollView.alpha = 0.f; + if (_style == LGAlertViewStyleAlert) + { + _scrollView.transform = CGAffineTransformMakeScale(0.95, 0.95); + _scrollView.alpha = 0.f; + + _styleView.transform = CGAffineTransformMakeScale(0.95, 0.95); + _styleView.alpha = 0.f; + } + else + { + _scrollView.center = _scrollViewCenterHidden; + + _styleView.center = _scrollViewCenterHidden; + } + + if (kLGAlertViewIsCancelButtonSeparate && _cancelButton) + { + _cancelButton.center = _cancelButtonCenterHidden; - _styleView.transform = CGAffineTransformMakeScale(0.95, 0.95); - _styleView.alpha = 0.f; + _styleCancelView.center = _cancelButtonCenterHidden; + } } - (void)dismissComplete { _window.hidden = YES; - [_windowPrevious makeKeyAndVisible]; + if ([kLGAlertViewWindowsArray.lastObject isEqual:_window]) + { + NSUInteger windowIndex = [kLGAlertViewWindowsArray indexOfObject:_window]; - // ----- + [kLGAlertViewWindowPrevious(windowIndex) makeKeyAndVisible]; + } - [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewDidDismissNotification object:self userInfo:nil]; + // ----- if (_didDismissHandler) _didDismissHandler(self); if (_delegate && [_delegate respondsToSelector:@selector(alertViewDidDismiss:)]) [_delegate alertViewDidDismiss:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewDidDismissNotification object:self userInfo:nil]; + // ----- + [kLGAlertViewWindowsArray removeObject:_window]; + _view = nil; _viewController = nil; - _windowNotice = nil; - _windowPrevious = nil; _window = nil; + _delegate = nil; } #pragma mark - - (void)subviewsInvalidateWithSize:(CGSize)size { - CGFloat width = kLGAlertViewWidth; + CGFloat width = (_style == LGAlertViewStyleAlert ? kLGAlertViewWidth : MIN(size.width, size.height)-kLGAlertViewOffsetHorizontal*2); if (_width > 0) { @@ -1527,18 +1744,19 @@ - (void)subviewsInvalidateWithSize:(CGSize)size _styleView = [UIView new]; _styleView.backgroundColor = _backgroundColor; _styleView.layer.masksToBounds = NO; - _styleView.layer.cornerRadius = _layerCornerRadius; + _styleView.layer.cornerRadius = _layerCornerRadius+(_layerCornerRadius == 0.f ? 0.f : _layerBorderWidth+1.f); _styleView.layer.borderColor = _layerBorderColor.CGColor; _styleView.layer.borderWidth = _layerBorderWidth; _styleView.layer.shadowColor = _layerShadowColor.CGColor; _styleView.layer.shadowRadius = _layerShadowRadius; - _styleView.layer.shadowOpacity = 1.f; - _styleView.layer.shadowOffset = CGSizeZero; + _styleView.layer.shadowOpacity = _layerShadowOpacity; + _styleView.layer.shadowOffset = _layerShadowOffset; [_view addSubview:_styleView]; _scrollView = [UIScrollView new]; _scrollView.backgroundColor = [UIColor clearColor]; _scrollView.indicatorStyle = _indicatorStyle; + _scrollView.showsVerticalScrollIndicator = _showsVerticalScrollIndicator; _scrollView.alwaysBounceVertical = NO; _scrollView.layer.masksToBounds = YES; _scrollView.layer.cornerRadius = _layerCornerRadius; @@ -1580,6 +1798,7 @@ - (void)subviewsInvalidateWithSize:(CGSize)size _messageLabel.font = _messageFont; if (!offsetY) offsetY = kLGAlertViewInnerMarginH/2; + else if (_style == LGAlertViewStyleActionSheet) offsetY -= kLGAlertViewInnerMarginH/3; CGSize messageLabelSize = [_messageLabel sizeThatFits:CGSizeMake(width-kLGAlertViewPaddingW*2, CGFLOAT_MAX)]; CGRect messageLabelFrame = CGRectMake(kLGAlertViewPaddingW, offsetY+kLGAlertViewInnerMarginH/2, width-kLGAlertViewPaddingW*2, messageLabelSize.height); @@ -1603,7 +1822,7 @@ - (void)subviewsInvalidateWithSize:(CGSize)size offsetY = _innerView.frame.origin.y+_innerView.frame.size.height; } - else if (_style == LGAlertViewStyleActivityIndicator) + else if (_type == LGAlertViewTypeActivityIndicator) { _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:_activityIndicatorViewStyle]; _activityIndicator.color = _activityIndicatorViewColor; @@ -1619,7 +1838,7 @@ - (void)subviewsInvalidateWithSize:(CGSize)size offsetY = _activityIndicator.frame.origin.y+_activityIndicator.frame.size.height; } - else if (_style == LGAlertViewStyleProgressView) + else if (_type == LGAlertViewTypeProgressView) { _progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]; _progressView.backgroundColor = [UIColor clearColor]; @@ -1657,7 +1876,7 @@ - (void)subviewsInvalidateWithSize:(CGSize)size offsetY = _progressLabel.frame.origin.y+_progressLabel.frame.size.height; } - else if (_style == LGAlertViewStyleTextFields) + else if (_type == LGAlertViewTypeTextFields) { for (NSUInteger i=0; i<_textFieldsArray.count; i++) { @@ -1690,18 +1909,47 @@ - (void)subviewsInvalidateWithSize:(CGSize)size offsetY -= kLGAlertViewInnerMarginH; } + // ----- + + if (kLGAlertViewIsCancelButtonSeparate && _cancelButtonTitle) + { + _styleCancelView = [UIView new]; + _styleCancelView.backgroundColor = _backgroundColor; + _styleCancelView.layer.masksToBounds = NO; + _styleCancelView.layer.cornerRadius = _layerCornerRadius+(_layerCornerRadius == 0.f ? 0.f : _layerBorderWidth+1.f);; + _styleCancelView.layer.borderColor = _layerBorderColor.CGColor; + _styleCancelView.layer.borderWidth = _layerBorderWidth; + _styleCancelView.layer.shadowColor = _layerShadowColor.CGColor; + _styleCancelView.layer.shadowRadius = _layerShadowRadius; + _styleCancelView.layer.shadowOpacity = _layerShadowOpacity; + _styleCancelView.layer.shadowOffset = _layerShadowOffset; + [_view insertSubview:_styleCancelView belowSubview:_scrollView]; + + [self cancelButtonInit]; + _cancelButton.layer.masksToBounds = YES; + _cancelButton.layer.cornerRadius = _layerCornerRadius; + [_view insertSubview:_cancelButton aboveSubview:_styleCancelView]; + } + + // ----- + NSUInteger numberOfButtons = _buttonTitles.count; if (_destructiveButtonTitle.length) numberOfButtons++; - if (_cancelButtonTitle.length) + if (_cancelButtonTitle.length && !kLGAlertViewIsCancelButtonSeparate) numberOfButtons++; BOOL showTable = NO; - if (numberOfButtons == 2) + if ((_style == LGAlertViewStyleAlert && numberOfButtons < 4) || + (_style == LGAlertViewStyleActionSheet && numberOfButtons == 1)) { - if (_destructiveButtonTitle.length) + CGFloat buttonWidth = kLGAlertViewWidth/numberOfButtons; + if (buttonWidth < kLGAlertViewButtonWidthMin) + showTable = YES; + + if (_destructiveButtonTitle.length && !showTable) { _destructiveButton = [UIButton new]; _destructiveButton.backgroundColor = [UIColor clearColor]; @@ -1714,6 +1962,7 @@ - (void)subviewsInvalidateWithSize:(CGSize)size [_destructiveButton setTitleColor:_destructiveButtonTitleColor forState:UIControlStateNormal]; [_destructiveButton setTitleColor:_destructiveButtonTitleColorHighlighted forState:UIControlStateHighlighted]; [_destructiveButton setTitleColor:_destructiveButtonTitleColorHighlighted forState:UIControlStateSelected]; + [_destructiveButton setBackgroundImage:[LGAlertView image1x1WithColor:_destructiveButtonBackgroundColor] forState:UIControlStateNormal]; [_destructiveButton setBackgroundImage:[LGAlertView image1x1WithColor:_destructiveButtonBackgroundColorHighlighted] forState:UIControlStateHighlighted]; [_destructiveButton setBackgroundImage:[LGAlertView image1x1WithColor:_destructiveButtonBackgroundColorHighlighted] forState:UIControlStateSelected]; _destructiveButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW); @@ -1728,42 +1977,21 @@ - (void)subviewsInvalidateWithSize:(CGSize)size CGSize size = [_destructiveButton sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; - if (size.width > kLGAlertViewWidth/2) + if (size.width > buttonWidth) showTable = YES; } - if (_cancelButtonTitle.length && !showTable) + if (_cancelButtonTitle.length && !kLGAlertViewIsCancelButtonSeparate && !showTable) { - _cancelButton = [UIButton new]; - _cancelButton.backgroundColor = [UIColor clearColor]; - _cancelButton.titleLabel.numberOfLines = _cancelButtonNumberOfLines; - _cancelButton.titleLabel.lineBreakMode = _cancelButtonLineBreakMode; - _cancelButton.titleLabel.adjustsFontSizeToFitWidth = _cancelButtonAdjustsFontSizeToFitWidth; - _cancelButton.titleLabel.minimumScaleFactor = _cancelButtonMinimumScaleFactor; - _cancelButton.titleLabel.font = _cancelButtonFont; - [_cancelButton setTitle:_cancelButtonTitle forState:UIControlStateNormal]; - [_cancelButton setTitleColor:_cancelButtonTitleColor forState:UIControlStateNormal]; - [_cancelButton setTitleColor:_cancelButtonTitleColorHighlighted forState:UIControlStateHighlighted]; - [_cancelButton setTitleColor:_cancelButtonTitleColorHighlighted forState:UIControlStateSelected]; - [_cancelButton setBackgroundImage:[LGAlertView image1x1WithColor:_cancelButtonBackgroundColorHighlighted] forState:UIControlStateHighlighted]; - [_cancelButton setBackgroundImage:[LGAlertView image1x1WithColor:_cancelButtonBackgroundColorHighlighted] forState:UIControlStateSelected]; - _cancelButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW); - _cancelButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - if (_cancelButtonTextAlignment == NSTextAlignmentCenter) - _cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; - else if (_cancelButtonTextAlignment == NSTextAlignmentLeft) - _cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; - else if (_cancelButtonTextAlignment == NSTextAlignmentRight) - _cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; - [_cancelButton addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside]; + [self cancelButtonInit]; CGSize size = [_cancelButton sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; - if (size.width > kLGAlertViewWidth/2) + if (size.width > buttonWidth) showTable = YES; } - if (_buttonTitles.count > 0 && !showTable) + if (_buttonTitles.count > 0 && !showTable) { _firstButton = [UIButton new]; _firstButton.backgroundColor = [UIColor clearColor]; @@ -1776,8 +2004,11 @@ - (void)subviewsInvalidateWithSize:(CGSize)size [_firstButton setTitleColor:_buttonsTitleColor forState:UIControlStateNormal]; [_firstButton setTitleColor:_buttonsTitleColorHighlighted forState:UIControlStateHighlighted]; [_firstButton setTitleColor:_buttonsTitleColorHighlighted forState:UIControlStateSelected]; + [_firstButton setTitleColor:_buttonsTitleColorDisabled forState:UIControlStateDisabled]; + [_firstButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColor] forState:UIControlStateNormal]; [_firstButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorHighlighted] forState:UIControlStateHighlighted]; [_firstButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorHighlighted] forState:UIControlStateSelected]; + [_firstButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorDisabled] forState:UIControlStateDisabled]; _firstButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW); _firstButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; if (_buttonsTextAlignment == NSTextAlignmentCenter) @@ -1786,11 +2017,12 @@ - (void)subviewsInvalidateWithSize:(CGSize)size _firstButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; else if (_buttonsTextAlignment == NSTextAlignmentRight) _firstButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; + _firstButton.enabled = (_disabledButtonIndex != 0); [_firstButton addTarget:self action:@selector(firstButtonAction) forControlEvents:UIControlEventTouchUpInside]; CGSize size = [_firstButton sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; - if (size.width > kLGAlertViewWidth/2) + if (size.width > buttonWidth) showTable = YES; if (_buttonTitles.count > 1 && !showTable) @@ -1806,8 +2038,11 @@ - (void)subviewsInvalidateWithSize:(CGSize)size [_secondButton setTitleColor:_buttonsTitleColor forState:UIControlStateNormal]; [_secondButton setTitleColor:_buttonsTitleColorHighlighted forState:UIControlStateHighlighted]; [_secondButton setTitleColor:_buttonsTitleColorHighlighted forState:UIControlStateSelected]; + [_secondButton setTitleColor:_buttonsTitleColorDisabled forState:UIControlStateDisabled]; + [_secondButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColor] forState:UIControlStateNormal]; [_secondButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorHighlighted] forState:UIControlStateHighlighted]; [_secondButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorHighlighted] forState:UIControlStateSelected]; + [_secondButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorDisabled] forState:UIControlStateDisabled]; _secondButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW); _secondButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; if (_buttonsTextAlignment == NSTextAlignmentCenter) @@ -1816,12 +2051,48 @@ - (void)subviewsInvalidateWithSize:(CGSize)size _secondButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; else if (_buttonsTextAlignment == NSTextAlignmentRight) _secondButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; + _secondButton.enabled = (_disabledButtonIndex != 1); [_secondButton addTarget:self action:@selector(secondButtonAction) forControlEvents:UIControlEventTouchUpInside]; CGSize size = [_secondButton sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; - if (size.width > kLGAlertViewWidth/2) + if (size.width > buttonWidth) showTable = YES; + + if (_buttonTitles.count > 2 && !showTable) + { + _thirdButton = [UIButton new]; + _thirdButton.backgroundColor = [UIColor clearColor]; + _thirdButton.titleLabel.numberOfLines = _buttonsNumberOfLines; + _thirdButton.titleLabel.lineBreakMode = _buttonsLineBreakMode; + _thirdButton.titleLabel.adjustsFontSizeToFitWidth = _buttonsAdjustsFontSizeToFitWidth; + _thirdButton.titleLabel.minimumScaleFactor = _buttonsMinimumScaleFactor; + _thirdButton.titleLabel.font = _buttonsFont; + [_thirdButton setTitle:_buttonTitles[2] forState:UIControlStateNormal]; + [_thirdButton setTitleColor:_buttonsTitleColor forState:UIControlStateNormal]; + [_thirdButton setTitleColor:_buttonsTitleColorHighlighted forState:UIControlStateHighlighted]; + [_thirdButton setTitleColor:_buttonsTitleColorHighlighted forState:UIControlStateSelected]; + [_thirdButton setTitleColor:_buttonsTitleColorDisabled forState:UIControlStateDisabled]; + [_thirdButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColor] forState:UIControlStateNormal]; + [_thirdButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorHighlighted] forState:UIControlStateHighlighted]; + [_thirdButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorHighlighted] forState:UIControlStateSelected]; + [_thirdButton setBackgroundImage:[LGAlertView image1x1WithColor:_buttonsBackgroundColorDisabled] forState:UIControlStateDisabled]; + _thirdButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW); + _thirdButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + if (_buttonsTextAlignment == NSTextAlignmentCenter) + _thirdButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; + else if (_buttonsTextAlignment == NSTextAlignmentLeft) + _thirdButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; + else if (_buttonsTextAlignment == NSTextAlignmentRight) + _thirdButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; + _thirdButton.enabled = (_disabledButtonIndex != 2); + [_thirdButton addTarget:self action:@selector(secondButtonAction) forControlEvents:UIControlEventTouchUpInside]; + + CGSize size = [_thirdButton sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; + + if (size.width > buttonWidth) + showTable = YES; + } } } @@ -1829,8 +2100,9 @@ - (void)subviewsInvalidateWithSize:(CGSize)size { UIButton *firstButton = nil; UIButton *secondButton = nil; + UIButton *thirdButton = nil; - if (_cancelButton) + if (_cancelButton && !kLGAlertViewIsCancelButtonSeparate) { [_scrollView addSubview:_cancelButton]; @@ -1850,13 +2122,22 @@ - (void)subviewsInvalidateWithSize:(CGSize)size [_scrollView addSubview:_firstButton]; if (!firstButton) firstButton = _firstButton; - else secondButton = _firstButton; + else if (!secondButton) secondButton = _firstButton; + else thirdButton = _firstButton; if (_secondButton) { [_scrollView addSubview:_secondButton]; - secondButton = _secondButton; + if (!secondButton) secondButton = _secondButton; + else thirdButton = _secondButton; + + if (_thirdButton) + { + [_scrollView addSubview:_thirdButton]; + + thirdButton = _thirdButton; + } } } @@ -1879,42 +2160,80 @@ - (void)subviewsInvalidateWithSize:(CGSize)size // ----- - _separatorVerticalView = [UIView new]; - _separatorVerticalView.backgroundColor = _separatorsColor; - - CGRect separatorVerticalViewFrame = CGRectMake(width/2, offsetY, kLGAlertViewSeparatorHeight, MAX(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height)); + CGRect firstButtonFrame = CGRectMake(0.f, offsetY, width/numberOfButtons, _buttonsHeight); if ([UIScreen mainScreen].scale == 1.f) - separatorVerticalViewFrame = CGRectIntegral(separatorVerticalViewFrame); + firstButtonFrame = CGRectIntegral(firstButtonFrame); + firstButton.frame = firstButtonFrame; - _separatorVerticalView.frame = separatorVerticalViewFrame; - [_scrollView addSubview:_separatorVerticalView]; + CGRect secondButtonFrame = CGRectZero; + CGRect thirdButtonFrame = CGRectZero; + if (secondButton) + { + secondButtonFrame = CGRectMake(firstButtonFrame.origin.x+firstButtonFrame.size.width+kLGAlertViewSeparatorHeight, offsetY, width/numberOfButtons-kLGAlertViewSeparatorHeight, _buttonsHeight); + if ([UIScreen mainScreen].scale == 1.f) + secondButtonFrame = CGRectIntegral(secondButtonFrame); + secondButton.frame = secondButtonFrame; + + if (thirdButton) + { + thirdButtonFrame = CGRectMake(secondButtonFrame.origin.x+secondButtonFrame.size.width+kLGAlertViewSeparatorHeight, offsetY, width/numberOfButtons-kLGAlertViewSeparatorHeight, _buttonsHeight); + if ([UIScreen mainScreen].scale == 1.f) + thirdButtonFrame = CGRectIntegral(thirdButtonFrame); + thirdButton.frame = thirdButtonFrame; + } + } // ----- - CGRect firstButtonFrame = CGRectMake(0.f, offsetY, width/2, _buttonsHeight); - if ([UIScreen mainScreen].scale == 1.f) - firstButtonFrame = CGRectIntegral(firstButtonFrame); - firstButton.frame = firstButtonFrame; + if (secondButton) + { + _separatorVerticalView1 = [UIView new]; + _separatorVerticalView1.backgroundColor = _separatorsColor; - CGRect secondButtonFrame = CGRectMake(width/2+kLGAlertViewSeparatorHeight, offsetY, width/2-kLGAlertViewSeparatorHeight, _buttonsHeight); - if ([UIScreen mainScreen].scale == 1.f) - secondButtonFrame = CGRectIntegral(secondButtonFrame); - secondButton.frame = secondButtonFrame; + CGRect separatorVerticalView1Frame = CGRectMake(firstButtonFrame.origin.x+firstButtonFrame.size.width, offsetY, kLGAlertViewSeparatorHeight, MAX(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height)); + if ([UIScreen mainScreen].scale == 1.f) + separatorVerticalView1Frame = CGRectIntegral(separatorVerticalView1Frame); - offsetY = firstButton.frame.origin.y+firstButton.frame.size.height; + _separatorVerticalView1.frame = separatorVerticalView1Frame; + [_scrollView addSubview:_separatorVerticalView1]; + + if (thirdButton) + { + _separatorVerticalView2 = [UIView new]; + _separatorVerticalView2.backgroundColor = _separatorsColor; + + CGRect separatorVerticalView2Frame = CGRectMake(secondButtonFrame.origin.x+secondButtonFrame.size.width, offsetY, kLGAlertViewSeparatorHeight, MAX(UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height)); + if ([UIScreen mainScreen].scale == 1.f) + separatorVerticalView2Frame = CGRectIntegral(separatorVerticalView2Frame); + + _separatorVerticalView2.frame = separatorVerticalView2Frame; + [_scrollView addSubview:_separatorVerticalView2]; + } + } + + // ----- + + offsetY += _buttonsHeight; } } else showTable = YES; if (showTable) { + if (!kLGAlertViewIsCancelButtonSeparate) + _cancelButton = nil; + _destructiveButton = nil; + _firstButton = nil; + _secondButton = nil; + _thirdButton = nil; + if (!_buttonTitles) _buttonTitles = [NSMutableArray new]; if (_destructiveButtonTitle.length) [_buttonTitles insertObject:_destructiveButtonTitle atIndex:0]; - if (_cancelButtonTitle.length) + if (_cancelButtonTitle.length && !kLGAlertViewIsCancelButtonSeparate) [_buttonTitles addObject:_cancelButtonTitle]; _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; @@ -1966,7 +2285,7 @@ - (void)layoutInvalidateWithSize:(CGSize)size // ----- - CGFloat width = kLGAlertViewWidth; + CGFloat width = (_style == LGAlertViewStyleAlert ? kLGAlertViewWidth : MIN(size.width, size.height)-kLGAlertViewOffsetHorizontal*2); if (_width > 0) { @@ -1977,14 +2296,19 @@ - (void)layoutInvalidateWithSize:(CGSize)size // ----- - CGFloat heightMax = size.height-_keyboardHeight-kLGAlertViewOffsetVertical; + CGFloat heightMax = size.height-_keyboardHeight-kLGAlertViewOffsetVertical*2; + + if (_windowLevel == LGAlertViewWindowLevelBelowStatusBar) + heightMax -= kLGAlertViewStatusBarHeight; if (_heightMax > 0 && _heightMax < heightMax) heightMax = _heightMax; - if (_cancelOnTouch && - !_cancelButtonTitle.length && - size.width < width+_buttonsHeight*2) + if (kLGAlertViewIsCancelButtonSeparate && _cancelButton) + heightMax -= (_buttonsHeight+_cancelButtonOffset); + else if (_cancelOnTouch && + !_cancelButtonTitle.length && + size.width < width+_buttonsHeight*2) heightMax -= _buttonsHeight*2; if (_scrollView.contentSize.height < heightMax) @@ -1996,15 +2320,31 @@ - (void)layoutInvalidateWithSize:(CGSize)size CGAffineTransform scrollViewTransform = CGAffineTransformIdentity; CGFloat scrollViewAlpha = 1.f; - scrollViewFrame = CGRectMake(size.width/2-width/2, size.height/2-_keyboardHeight/2-heightMax/2, width, heightMax); + if (_style == LGAlertViewStyleAlert) + { + scrollViewFrame = CGRectMake(size.width/2-width/2, size.height/2-_keyboardHeight/2-heightMax/2, width, heightMax); + + if (_windowLevel == LGAlertViewWindowLevelBelowStatusBar) + scrollViewFrame.origin.y += kLGAlertViewStatusBarHeight/2; + + if (!self.isShowing) + { + scrollViewTransform = CGAffineTransformMakeScale(1.2, 1.2); - if (!self.isShowing) + scrollViewAlpha = 0.f; + } + } + else { - scrollViewTransform = CGAffineTransformMakeScale(1.2, 1.2); + CGFloat bottomShift = kLGAlertViewOffsetVertical; + if (kLGAlertViewIsCancelButtonSeparate && _cancelButton) + bottomShift += _buttonsHeight+_cancelButtonOffset; - scrollViewAlpha = 0.f; + scrollViewFrame = CGRectMake(size.width/2-width/2, size.height-bottomShift-heightMax, width, heightMax); } + // ----- + if ([UIScreen mainScreen].scale == 1.f) { scrollViewFrame = CGRectIntegral(scrollViewFrame); @@ -2016,8 +2356,57 @@ - (void)layoutInvalidateWithSize:(CGSize)size } else { - if (_separatorVerticalView && _separatorVerticalView.frame.origin.y+_buttonsHeight < scrollViewFrame.size.height) - scrollViewFrame.size.height = _separatorVerticalView.frame.origin.y+_buttonsHeight; + if (_separatorVerticalView1 && _separatorVerticalView1.frame.origin.y+_buttonsHeight < scrollViewFrame.size.height) + scrollViewFrame.size.height = _separatorVerticalView1.frame.origin.y+_buttonsHeight; + } + } + + // ----- + + if (_style == LGAlertViewStyleActionSheet) + { + CGRect cancelButtonFrame = CGRectZero; + if (kLGAlertViewIsCancelButtonSeparate && _cancelButton) + { + cancelButtonFrame = CGRectMake(size.width/2-width/2, size.height-_cancelButtonOffset-_buttonsHeight, width, _buttonsHeight); + if ([UIScreen mainScreen].scale == 1.f) + cancelButtonFrame = CGRectIntegral(cancelButtonFrame); + } + + _scrollViewCenterShowed = CGPointMake(scrollViewFrame.origin.x+scrollViewFrame.size.width/2, scrollViewFrame.origin.y+scrollViewFrame.size.height/2); + _cancelButtonCenterShowed = CGPointMake(cancelButtonFrame.origin.x+cancelButtonFrame.size.width/2, cancelButtonFrame.origin.y+cancelButtonFrame.size.height/2); + + // ----- + + CGFloat commonHeight = scrollViewFrame.size.height+kLGAlertViewOffsetVertical; + if (kLGAlertViewIsCancelButtonSeparate && _cancelButton) + commonHeight += _buttonsHeight+_cancelButtonOffset; + + _scrollViewCenterHidden = CGPointMake(scrollViewFrame.origin.x+scrollViewFrame.size.width/2, scrollViewFrame.origin.y+scrollViewFrame.size.height/2+commonHeight+_layerBorderWidth+_layerShadowRadius); + _cancelButtonCenterHidden = CGPointMake(cancelButtonFrame.origin.x+cancelButtonFrame.size.width/2, cancelButtonFrame.origin.y+cancelButtonFrame.size.height/2+commonHeight); + + if (!self.isShowing) + { + scrollViewFrame.origin.y += commonHeight; + if ([UIScreen mainScreen].scale == 1.f) + scrollViewFrame = CGRectIntegral(scrollViewFrame); + + if (kLGAlertViewIsCancelButtonSeparate && _cancelButton) + { + cancelButtonFrame.origin.y += commonHeight; + if ([UIScreen mainScreen].scale == 1.f) + cancelButtonFrame = CGRectIntegral(cancelButtonFrame); + } + } + + // ----- + + if (kLGAlertViewIsCancelButtonSeparate && _cancelButton) + { + _cancelButton.frame = cancelButtonFrame; + + CGFloat borderWidth = _layerBorderWidth; + _styleCancelView.frame = CGRectMake(cancelButtonFrame.origin.x-borderWidth, cancelButtonFrame.origin.y-borderWidth, cancelButtonFrame.size.width+borderWidth*2, cancelButtonFrame.size.height+borderWidth*2); } } @@ -2033,6 +2422,33 @@ - (void)layoutInvalidateWithSize:(CGSize)size _styleView.alpha = scrollViewAlpha; } +- (void)cancelButtonInit +{ + _cancelButton = [UIButton new]; + _cancelButton.backgroundColor = [UIColor clearColor]; + _cancelButton.titleLabel.numberOfLines = _cancelButtonNumberOfLines; + _cancelButton.titleLabel.lineBreakMode = _cancelButtonLineBreakMode; + _cancelButton.titleLabel.adjustsFontSizeToFitWidth = _cancelButtonAdjustsFontSizeToFitWidth; + _cancelButton.titleLabel.minimumScaleFactor = _cancelButtonMinimumScaleFactor; + _cancelButton.titleLabel.font = _cancelButtonFont; + [_cancelButton setTitle:_cancelButtonTitle forState:UIControlStateNormal]; + [_cancelButton setTitleColor:_cancelButtonTitleColor forState:UIControlStateNormal]; + [_cancelButton setTitleColor:_cancelButtonTitleColorHighlighted forState:UIControlStateHighlighted]; + [_cancelButton setTitleColor:_cancelButtonTitleColorHighlighted forState:UIControlStateSelected]; + [_cancelButton setBackgroundImage:[LGAlertView image1x1WithColor:_cancelButtonBackgroundColor] forState:UIControlStateNormal]; + [_cancelButton setBackgroundImage:[LGAlertView image1x1WithColor:_cancelButtonBackgroundColorHighlighted] forState:UIControlStateHighlighted]; + [_cancelButton setBackgroundImage:[LGAlertView image1x1WithColor:_cancelButtonBackgroundColorHighlighted] forState:UIControlStateSelected]; + _cancelButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW); + _cancelButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + if (_cancelButtonTextAlignment == NSTextAlignmentCenter) + _cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; + else if (_cancelButtonTextAlignment == NSTextAlignmentLeft) + _cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; + else if (_cancelButtonTextAlignment == NSTextAlignmentRight) + _cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; + [_cancelButton addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside]; +} + #pragma mark - - (void)cancelAction:(id)sender @@ -2042,18 +2458,20 @@ - (void)cancelAction:(id)sender if (onButton) [(UIButton *)sender setSelected:YES]; - [self dismissAnimated:YES completionHandler:nil]; - // ----- + if (_cancelHandler) _cancelHandler(self, onButton); + + if (_delegate && [_delegate respondsToSelector:@selector(alertViewCancelled:)]) + [_delegate alertViewCancelled:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewCancelNotification object:self userInfo:@{@"onButton" : [NSNumber numberWithBool:onButton]}]; - if (_cancelHandler) _cancelHandler(self, onButton); + // ----- - if (_delegate && [_delegate respondsToSelector:@selector(alertViewCancelled:)]) - [_delegate alertViewCancelled:self]; + [self dismissAnimated:YES completionHandler:nil]; } - (void)destructiveAction:(id)sender @@ -2061,62 +2479,93 @@ - (void)destructiveAction:(id)sender if (sender && [sender isKindOfClass:[UIButton class]]) [(UIButton *)sender setSelected:YES]; - [self dismissAnimated:YES completionHandler:nil]; - // ----- - [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewDestructiveNotification object:self userInfo:nil]; - if (_destructiveHandler) _destructiveHandler(self); if (_delegate && [_delegate respondsToSelector:@selector(alertViewDestructiveButtonPressed:)]) [_delegate alertViewDestructiveButtonPressed:self]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewDestructiveNotification object:self userInfo:nil]; + + // ----- + + [self dismissAnimated:YES completionHandler:nil]; } - (void)firstButtonAction { _firstButton.selected = YES; - [self dismissAnimated:YES completionHandler:nil]; - NSUInteger index = 0; NSString *title = _buttonTitles[0]; // ----- + if (_actionHandler) _actionHandler(self, title, index); + + if (_delegate && [_delegate respondsToSelector:@selector(alertView:buttonPressedWithTitle:index:)]) + [_delegate alertView:self buttonPressedWithTitle:title index:index]; + [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewActionNotification object:self userInfo:@{@"title" : title, @"index" : [NSNumber numberWithInteger:index]}]; - if (_actionHandler) _actionHandler(self, title, index); + // ----- - if (_delegate && [_delegate respondsToSelector:@selector(alertView:buttonPressedWithTitle:index:)]) - [_delegate alertView:self buttonPressedWithTitle:title index:index]; + [self dismissAnimated:YES completionHandler:nil]; } - (void)secondButtonAction { _secondButton.selected = YES; - [self dismissAnimated:YES completionHandler:nil]; - NSUInteger index = 1; NSString *title = _buttonTitles[1]; // ----- + if (_actionHandler) _actionHandler(self, title, index); + + if (_delegate && [_delegate respondsToSelector:@selector(alertView:buttonPressedWithTitle:index:)]) + [_delegate alertView:self buttonPressedWithTitle:title index:index]; + [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewActionNotification object:self userInfo:@{@"title" : title, @"index" : [NSNumber numberWithInteger:index]}]; - if (_actionHandler) _actionHandler(self, title, index); + // ----- + [self dismissAnimated:YES completionHandler:nil]; +} + +- (void)thirdButtonAction +{ + _thirdButton.selected = YES; + + NSUInteger index = 2; + + NSString *title = _buttonTitles[2]; + + // ----- + + if (_actionHandler) _actionHandler(self, title, index); + if (_delegate && [_delegate respondsToSelector:@selector(alertView:buttonPressedWithTitle:index:)]) [_delegate alertView:self buttonPressedWithTitle:title index:index]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kLGAlertViewActionNotification + object:self + userInfo:@{@"title" : title, + @"index" : [NSNumber numberWithInteger:index]}]; + + // ----- + + [self dismissAnimated:YES completionHandler:nil]; } #pragma mark - Support @@ -2145,36 +2594,38 @@ + (void)animateStandardWithAnimations:(void(^)())animations completion:(void(^)( + (UIImage *)image1x1WithColor:(UIColor *)color { + if (!color) return nil; + CGRect rect = CGRectMake(0.f, 0.f, 1.f, 1.f); - + UIGraphicsBeginImageContext(rect.size); - + CGContextRef context = UIGraphicsGetCurrentContext(); - + CGContextSetFillColorWithColor(context, color.CGColor); CGContextFillRect(context, rect); - + UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); - + return image; } + (void)keyboardAnimateWithNotificationUserInfo:(NSDictionary *)notificationUserInfo animations:(void(^)(CGFloat keyboardHeight))animations { CGFloat keyboardHeight = (notificationUserInfo[UIKeyboardFrameEndUserInfoKey] ? [notificationUserInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height : 0.f); - + if (!keyboardHeight) return; - + NSTimeInterval animationDuration = [notificationUserInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; int animationCurve = [notificationUserInfo[UIKeyboardAnimationCurveUserInfoKey] intValue]; - + [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:animationDuration]; [UIView setAnimationCurve:animationCurve]; - + if (animations) animations(keyboardHeight); - + [UIView commitAnimations]; } diff --git a/LGAlertView/LGAlertViewCell.h b/LGAlertView/LGAlertViewCell.h index ebd9383..c5a7d49 100644 --- a/LGAlertView/LGAlertViewCell.h +++ b/LGAlertView/LGAlertViewCell.h @@ -31,12 +31,15 @@ @interface LGAlertViewCell : UITableViewCell -@property (strong, nonatomic) NSString *title; +@property (strong, nonatomic) NSString *title; @property (strong, nonatomic) UIColor *titleColor; @property (strong, nonatomic) UIColor *titleColorHighlighted; +@property (strong, nonatomic) UIColor *titleColorDisabled; +@property (strong, nonatomic) UIColor *backgroundColorNormal; @property (strong, nonatomic) UIColor *backgroundColorHighlighted; +@property (strong, nonatomic) UIColor *backgroundColorDisabled; @property (assign, nonatomic, getter=isSeparatorVisible) BOOL separatorVisible; @property (strong, nonatomic) UIColor *separatorColor_; @@ -48,4 +51,6 @@ @property (assign, nonatomic) BOOL adjustsFontSizeToFitWidth; @property (assign, nonatomic) CGFloat minimumScaleFactor; +@property (assign, nonatomic) BOOL enabled; + @end diff --git a/LGAlertView/LGAlertViewCell.m b/LGAlertView/LGAlertViewCell.m index 44414db..4a59fe0 100644 --- a/LGAlertView/LGAlertViewCell.m +++ b/LGAlertView/LGAlertViewCell.m @@ -53,6 +53,8 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSStr _separatorView = [UIView new]; [self addSubview:_separatorView]; + + _enabled = YES; } return self; } @@ -98,8 +100,7 @@ - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated } else { - _titleLabel.textColor = _titleColor; - self.backgroundColor = [UIColor clearColor]; + [self setEnabled:_enabled]; } } @@ -113,9 +114,26 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated self.backgroundColor = _backgroundColorHighlighted; } else + { + [self setEnabled:_enabled]; + } +} + +- (void)setEnabled:(BOOL)enabled +{ + _enabled = enabled; + + self.userInteractionEnabled = enabled; + + if (enabled) { _titleLabel.textColor = _titleColor; - self.backgroundColor = [UIColor clearColor]; + self.backgroundColor = _backgroundColorNormal; + } + else + { + _titleLabel.textColor = _titleColorDisabled; + self.backgroundColor = _backgroundColorDisabled; } } diff --git a/LGAlertView/LGAlertViewController.h b/LGAlertView/LGAlertViewController.h new file mode 100644 index 0000000..5b0a6f3 --- /dev/null +++ b/LGAlertView/LGAlertViewController.h @@ -0,0 +1,17 @@ +// +// LGAlertViewController.h +// Pods +// +// Created by Grigory Lutkov on 01.11.15. +// +// + +#import + +@class LGAlertView; + +@interface LGAlertViewController : UIViewController + +- (instancetype)initWithAlertView:(LGAlertView *)alertView view:(UIView *)view; + +@end diff --git a/LGAlertView/LGAlertViewController.m b/LGAlertView/LGAlertViewController.m new file mode 100644 index 0000000..b38655d --- /dev/null +++ b/LGAlertView/LGAlertViewController.m @@ -0,0 +1,95 @@ +// +// LGAlertViewController.m +// Pods +// +// Created by Grigory Lutkov on 01.11.15. +// +// + +#import "LGAlertViewController.h" +#import "LGAlertView.h" +#import "UIWindow+LGAlertView.h" + +@interface LGAlertViewController () + +@property (strong, nonatomic) LGAlertView *alertView; + +@end + +@implementation LGAlertViewController + +- (instancetype)initWithAlertView:(LGAlertView *)alertView view:(UIView *)view +{ + self = [super init]; + if (self) + { +#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0 + if ([UIDevice currentDevice].systemVersion.floatValue < 7.0) + self.wantsFullScreenLayout = YES; +#endif + + _alertView = alertView; + + self.view.backgroundColor = [UIColor clearColor]; + [self.view addSubview:view]; + } + return self; +} + +- (BOOL)shouldAutorotate +{ + UIWindow *window = [UIApplication sharedApplication].delegate.window; + + return window.currentViewController.shouldAutorotate; +} + +- (UIInterfaceOrientationMask)supportedInterfaceOrientations +{ + UIWindow *window = [UIApplication sharedApplication].delegate.window; + + return window.currentViewController.supportedInterfaceOrientations; +} + +#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_6_0 + +// iOS <= 7 + +- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration +{ + [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; + + CGSize size = self.view.frame.size; + + if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) + size = CGSizeMake(MIN(size.width, size.height), MAX(size.width, size.height)); + else + size = CGSizeMake(MAX(size.width, size.height), MIN(size.width, size.height)); + + [_alertView layoutInvalidateWithSize:size]; +} + +#endif + +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0 + +// iOS >= 8 + +- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator +{ + [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; + + [coordinator animateAlongsideTransition:^(id context) + { + [_alertView layoutInvalidateWithSize:size]; + } + completion:nil]; +} + +#endif + +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return [UIApplication sharedApplication].statusBarStyle; +} + +@end diff --git a/LGAlertView/LGAlertViewWindow.h b/LGAlertView/LGAlertViewWindow.h new file mode 100644 index 0000000..e520bdd --- /dev/null +++ b/LGAlertView/LGAlertViewWindow.h @@ -0,0 +1,34 @@ +// +// LGAlertViewWindow.h +// LGAlertView +// +// +// The MIT License (MIT) +// +// Copyright (c) 2015 Grigory Lutkov +// (https://github.com/Friend-LGA/LGAlertView) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +#import + +@interface LGAlertViewWindow : UIWindow + +@end diff --git a/LGAlertView/LGAlertViewWindow.m b/LGAlertView/LGAlertViewWindow.m new file mode 100644 index 0000000..172a31c --- /dev/null +++ b/LGAlertView/LGAlertViewWindow.m @@ -0,0 +1,34 @@ +// +// LGAlertViewWindow.m +// LGAlertView +// +// +// The MIT License (MIT) +// +// Copyright (c) 2015 Grigory Lutkov +// (https://github.com/Friend-LGA/LGAlertView) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// + +#import "LGAlertViewWindow.h" + +@implementation LGAlertViewWindow + +@end diff --git a/LGAlertView/UIWindow+LGAlertView.h b/LGAlertView/UIWindow+LGAlertView.h new file mode 100644 index 0000000..99b14a5 --- /dev/null +++ b/LGAlertView/UIWindow+LGAlertView.h @@ -0,0 +1,15 @@ +// +// UIWindow+LGAlertView.h +// Pods +// +// Created by Grigory Lutkov on 01.11.15. +// +// + +#import + +@interface UIWindow (LGAlertView) + +- (UIViewController *)currentViewController; + +@end diff --git a/LGAlertView/UIWindow+LGAlertView.m b/LGAlertView/UIWindow+LGAlertView.m new file mode 100644 index 0000000..7d072a0 --- /dev/null +++ b/LGAlertView/UIWindow+LGAlertView.m @@ -0,0 +1,28 @@ +// +// UIWindow+LGAlertView.m +// Pods +// +// Created by Grigory Lutkov on 01.11.15. +// +// + +#import "UIWindow+LGAlertView.h" + +@implementation UIWindow (LGAlertView) + +- (NSString *)className +{ + return NSStringFromClass([self class]); +} + +- (UIViewController *)currentViewController +{ + UIViewController *viewController = self.rootViewController; + + if (viewController.presentedViewController) + viewController = viewController.presentedViewController; + + return viewController; +} + +@end diff --git a/README.md b/README.md index 69f3084..e444fe7 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,51 @@ # LGAlertView -Customizable implementation of UIAlertView. +Customizable implementation of UIAlertViewController, UIAlertView and UIActionSheet. All in one. +You can customize every detail. Make AlertView of your dream! :) ## Preview - - - - - - - - - +### Default Alert View Style + + + + + + + + + + + + + +### Default Action Sheet Style + + + + + + + + + +### Custom Alert View Styles + + + + + + + + +### Custom Action Sheet Styles + + + + + + + ## Installation @@ -28,7 +61,7 @@ Customizable implementation of UIAlertView. ``` platform :ios, '6.0' -pod 'LGAlertView', '~> 1.0.0' +pod 'LGAlertView', '~> 2.0.0' ``` ## Usage @@ -46,44 +79,48 @@ You have several methods for initialization: ```objective-c - (instancetype)initWithTitle:(NSString *)title message:(NSString *)message + style:(LGAlertViewStyle)style buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; -- (instancetype)initWithViewStyleWithTitle:(NSString *)title +- (instancetype)initWithViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + view:(UIView *)view + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle; + +- (instancetype)initWithActivityIndicatorAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle; + +- (instancetype)initWithProgressViewAndTitle:(NSString *)title + message:(NSString *)message + style:(LGAlertViewStyle)style + progressLabelText:(NSString *)progressLabelText + buttonTitles:(NSArray *)buttonTitles + cancelButtonTitle:(NSString *)cancelButtonTitle + destructiveButtonTitle:(NSString *)destructiveButtonTitle; + +- (instancetype)initWithTextFieldsAndTitle:(NSString *)title message:(NSString *)message - view:(UIView *)view + numberOfTextFields:(NSUInteger)numberOfTextFields + textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler buttonTitles:(NSArray *)buttonTitles cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle; - -- (instancetype)initWithActivityIndicatorStyleWithTitle:(NSString *)title - message:(NSString *)message - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle; - -- (instancetype)initWithProgressViewStyleWithTitle:(NSString *)title - message:(NSString *)message - progressLabelText:(NSString *)progressLabelText - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle; - -- (instancetype)initWithTextFieldsStyleWithTitle:(NSString *)title - message:(NSString *)message - numberOfTextFields:(NSUInteger)numberOfTextFields - textFieldsSetupHandler:(void(^)(UITextField *textField, NSUInteger index))textFieldsSetupHandler - buttonTitles:(NSArray *)buttonTitles - cancelButtonTitle:(NSString *)cancelButtonTitle - destructiveButtonTitle:(NSString *)destructiveButtonTitle; ``` More init methods you can find in [LGAlertView.h](https://github.com/Friend-LGA/LGAlertView/blob/master/LGAlertView/LGAlertView.h) ### Handle actions -To handle actions you can use initialization methods with blocks or delegate, or implement it after initialization. +To handle actions you can use blocks, delegate, or notifications: #### Delegate @@ -113,13 +150,14 @@ To handle actions you can use initialization methods with blocks or delegate, or #### Notifications -Here is also some notifications, that you can add to NSNotificationsCenter: - ```objective-c kLGAlertViewWillShowNotification; kLGAlertViewWillDismissNotification; kLGAlertViewDidShowNotification; kLGAlertViewDidDismissNotification; +kLGAlertViewActionNotification; +kLGAlertViewCancelNotification; +kLGAlertViewDestructiveNotification; ``` ### More