diff --git a/Demo/LGAlertViewDemo/TableViewControllerActionSheet.m b/Demo/LGAlertViewDemo/TableViewControllerActionSheet.m index f5e04d1..c2371d4 100644 --- a/Demo/LGAlertViewDemo/TableViewControllerActionSheet.m +++ b/Demo/LGAlertViewDemo/TableViewControllerActionSheet.m @@ -37,7 +37,13 @@ - (id)init @"LGAlertView + ActivityIndicator", @"LGAlertView + ActivityIndicator cancel", @"LGAlertView + ProgressView cancel", - @"LGAlertView + Transition"]; + @"", + @"LGAlertView + Transition 1", + @"LGAlertView + Transition 2", + @"LGAlertView + Transition 3", + @"LGAlertView + Transition 4", + @"LGAlertView + Transition 5", + @"LGAlertView + Transition 6"]; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; UIEdgeInsets contentInset = self.tableView.contentInset; @@ -120,9 +126,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:@[@"Button 1", @"Button 2"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }] showAnimated:YES completionHandler:nil]; } else if (indexPath.row == 4) { @@ -133,9 +145,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath @"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]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }] showAnimated:YES completionHandler:nil]; } else if (indexPath.row == 5) { @@ -146,9 +164,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath @"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]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; alertView.buttonsNumberOfLines = 0; [alertView showAnimated:YES completionHandler:nil]; } @@ -160,9 +184,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:@[@"Blue pill"] cancelButtonTitle:nil destructiveButtonTitle:@"Red pill" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; alertView.cancelOnTouch = NO; [alertView showAnimated:YES completionHandler:nil]; } @@ -197,9 +227,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath @"Button 25"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; alertView.windowLevel = LGAlertViewWindowLevelBelowStatusBar; [alertView showAnimated:YES completionHandler:nil]; } @@ -234,9 +270,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath @"Button 25"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; alertView.heightMax = 256.f; [alertView showAnimated:YES completionHandler:nil]; } @@ -253,9 +295,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:@[@"Done"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }] showAnimated:YES completionHandler:nil]; } else if (indexPath.row == 10) { @@ -283,9 +331,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:nil cancelButtonTitle:@"I'm hurry" destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; [alertView showAnimated:YES completionHandler:nil]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) @@ -302,14 +356,180 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:nil cancelButtonTitle:@"I'm hurry" destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; [alertView showAnimated:YES completionHandler:nil]; [self updateProgressWithAlertView:alertView]; } - else if (indexPath.row == 13) + else if (indexPath.row == 14) + { + LGAlertView *alertView1 = [[LGAlertView alloc] initWithActivityIndicatorAndTitle:@"Loading" + message:@"Waiting please" + style:LGAlertViewStyleActionSheet + buttonTitles:nil + cancelButtonTitle:@"I'm hurry" + destructiveButtonTitle:nil + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + [alertView1 showAnimated:YES completionHandler:nil]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) + { + LGAlertView *alertView2 = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button 1", @"Button 2"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + + [alertView1 transitionToAlertView:alertView2 completionHandler:nil]; + }); + } + else if (indexPath.row == 15) + { + LGAlertView *alertView1 = [[LGAlertView alloc] initWithActivityIndicatorAndTitle:@"Loading" + message:@"Waiting please" + style:LGAlertViewStyleActionSheet + buttonTitles:nil + cancelButtonTitle:nil + destructiveButtonTitle:nil + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + [alertView1 showAnimated:YES completionHandler:nil]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) + { + LGAlertView *alertView2 = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button 1", @"Button 2"] + cancelButtonTitle:nil + destructiveButtonTitle:@"Destructive" + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + + [alertView1 transitionToAlertView:alertView2 completionHandler:nil]; + }); + } + else if (indexPath.row == 16) + { + LGAlertView *alertView1 = [[LGAlertView alloc] initWithActivityIndicatorAndTitle:@"Loading" + message:@"Waiting please" + style:LGAlertViewStyleActionSheet + buttonTitles:nil + cancelButtonTitle:@"I'm hurry" + destructiveButtonTitle:nil + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + [alertView1 showAnimated:YES completionHandler:nil]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) + { + LGAlertView *alertView2 = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button 1", @"Button 2"] + cancelButtonTitle:nil + destructiveButtonTitle:@"Destructive" + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + + [alertView1 transitionToAlertView:alertView2 completionHandler:nil]; + }); + } + else if (indexPath.row == 17) + { + LGAlertView *alertView1 = [[LGAlertView alloc] initWithActivityIndicatorAndTitle:@"Loading" + message:@"Waiting please" + style:LGAlertViewStyleActionSheet + buttonTitles:nil + cancelButtonTitle:nil + destructiveButtonTitle:nil + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + [alertView1 showAnimated:YES completionHandler:nil]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) + { + LGAlertView *alertView2 = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button 1", @"Button 2"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + + [alertView1 transitionToAlertView:alertView2 completionHandler:nil]; + }); + } + else if (indexPath.row == 18) { LGAlertView *alertView1 = [[LGAlertView alloc] initWithActivityIndicatorAndTitle:@"Loading" message:@"Waiting please" @@ -317,9 +537,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:nil cancelButtonTitle:@"I'm hurry" destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; [alertView1 showAnimated:YES completionHandler:nil]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) @@ -330,9 +556,55 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:@[@"Button 1", @"Button 2"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + + [alertView1 transitionToAlertView:alertView2 completionHandler:nil]; + }); + } + else if (indexPath.row == 19) + { + LGAlertView *alertView1 = [[LGAlertView alloc] initWithActivityIndicatorAndTitle:@"Loading" + message:@"Waiting please" + style:LGAlertViewStyleActionSheet + buttonTitles:nil + cancelButtonTitle:nil + destructiveButtonTitle:nil + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + [alertView1 showAnimated:YES completionHandler:nil]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) + { + LGAlertView *alertView2 = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Button 1", @"Button 2"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; [alertView1 transitionToAlertView:alertView2 completionHandler:nil]; }); @@ -355,7 +627,7 @@ - (void)updateProgressWithAlertView:(LGAlertView *)alertView progress = 1.f; [alertView setProgress:progress progressLabelText:[NSString stringWithFormat:@"%.0f %%", progress*100]]; - + [self updateProgressWithAlertView:alertView]; } }); diff --git a/Demo/LGAlertViewDemo/TableViewControllerAlert.m b/Demo/LGAlertViewDemo/TableViewControllerAlert.m index 44fcaaa..e19cf1e 100644 --- a/Demo/LGAlertViewDemo/TableViewControllerAlert.m +++ b/Demo/LGAlertViewDemo/TableViewControllerAlert.m @@ -43,7 +43,10 @@ - (id)init @"LGAlertView + ActivityIndicator", @"LGAlertView + ActivityIndicator cancel", @"LGAlertView + ProgressView cancel", - @"LGAlertView + Transition"]; + @"", + @"LGAlertView + Transition 1", + @"LGAlertView + Transition 2", + @"LGAlertView + Transition 3"]; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; UIEdgeInsets contentInset = self.tableView.contentInset; @@ -126,9 +129,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:nil cancelButtonTitle:@"OK" destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }] showAnimated:YES completionHandler:nil]; } else if (indexPath.row == 4) { @@ -138,9 +147,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }] showAnimated:YES completionHandler:nil]; } else if (indexPath.row == 5) { @@ -150,9 +165,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:@[@"1 - A", @"2 - B", @"3 - C"] cancelButtonTitle:nil destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }] showAnimated:YES completionHandler:nil]; } else if (indexPath.row == 6) { @@ -162,9 +183,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:@[@"Button 1", @"Button 2"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }] showAnimated:YES completionHandler:nil]; } else if (indexPath.row == 7) { @@ -175,9 +202,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath @"Other button 2 with longest title text ever exists"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }] showAnimated:YES completionHandler:nil]; } else if (indexPath.row == 8) { @@ -188,9 +221,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath @"Other button 2 with longest title text ever exists"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; alertView.buttonsNumberOfLines = 0; [alertView showAnimated:YES completionHandler:nil]; } @@ -202,9 +241,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:@[@"Blue pill"] cancelButtonTitle:nil destructiveButtonTitle:@"Red pill" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; alertView.cancelOnTouch = NO; [alertView showAnimated:YES completionHandler:nil]; } @@ -239,9 +284,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath @"Button 25"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; alertView.windowLevel = LGAlertViewWindowLevelBelowStatusBar; [alertView showAnimated:YES completionHandler:nil]; } @@ -276,39 +327,51 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath @"Button 25"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; 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) + message:@"Enter your login and password" + numberOfTextFields:2 + textFieldsSetupHandler:^(UITextField *textField, NSUInteger index) + { + if (index == 0) + textField.placeholder = @"Login"; + else if (index == 1) { - 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; + textField.placeholder = @"Password"; + textField.secureTextEntry = YES; } - buttonTitles:@[@"Done"] - cancelButtonTitle:@"Cancel" - destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + + textField.tag = index; + textField.delegate = self; + textField.enablesReturnKeyAutomatically = YES; + textField.autocapitalizationType = NO; + textField.autocorrectionType = NO; + } + buttonTitles:@[@"Done"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:nil + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; [_securityAlertView setButtonAtIndex:0 enabled:NO]; [_securityAlertView showAnimated:YES completionHandler:nil]; } @@ -324,9 +387,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:@[@"Done"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; alertView.windowLevel = LGAlertViewWindowLevelBelowStatusBar; [alertView showAnimated:YES completionHandler:nil]; } @@ -343,9 +412,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:@[@"Done"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil] showAnimated:YES completionHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }] showAnimated:YES completionHandler:nil]; } else if (indexPath.row == 15) { @@ -355,9 +430,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:nil cancelButtonTitle:nil destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; [alertView showAnimated:YES completionHandler:nil]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) @@ -373,9 +454,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:nil cancelButtonTitle:@"I'm hurry" destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; [alertView showAnimated:YES completionHandler:nil]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) @@ -392,24 +479,116 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:nil cancelButtonTitle:@"I'm hurry" destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; [alertView showAnimated:YES completionHandler:nil]; [self updateProgressWithAlertView:alertView]; } - else if (indexPath.row == 18) + else if (indexPath.row == 19) { LGAlertView *alertView1 = [[LGAlertView alloc] initWithActivityIndicatorAndTitle:@"Loading" - message:@"Waiting please" - style:LGAlertViewStyleAlert - buttonTitles:nil - cancelButtonTitle:@"I'm hurry" - destructiveButtonTitle:nil - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + message:@"Waiting please" + style:LGAlertViewStyleAlert + buttonTitles:nil + cancelButtonTitle:@"I'm hurry" + destructiveButtonTitle:nil + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + [alertView1 showAnimated:YES completionHandler:nil]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) + { + LGAlertView *alertView2 = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleAlert + buttonTitles:@[@"Button 1", @"Button 2"] + cancelButtonTitle:@"Cancel" + destructiveButtonTitle:@"Destructive" + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + + [alertView1 transitionToAlertView:alertView2 completionHandler:nil]; + }); + } + else if (indexPath.row == 20) + { + LGAlertView *alertView1 = [[LGAlertView alloc] initWithActivityIndicatorAndTitle:@"Loading" + message:@"Waiting please" + style:LGAlertViewStyleAlert + buttonTitles:nil + cancelButtonTitle:@"I'm hurry" + destructiveButtonTitle:nil + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + [alertView1 showAnimated:YES completionHandler:nil]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) + { + LGAlertView *alertView2 = [[LGAlertView alloc] initWithTitle:@"Title" + message:@"Message" + style:LGAlertViewStyleActionSheet + buttonTitles:@[@"Button 1", @"Button 2"] + cancelButtonTitle:nil + destructiveButtonTitle:@"Destructive" + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; + + [alertView1 transitionToAlertView:alertView2 completionHandler:nil]; + }); + } + else if (indexPath.row == 21) + { + LGAlertView *alertView1 = [[LGAlertView alloc] initWithActivityIndicatorAndTitle:@"Loading" + message:@"Waiting please" + style:LGAlertViewStyleAlert + buttonTitles:nil + cancelButtonTitle:@"I'm hurry" + destructiveButtonTitle:nil + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; [alertView1 showAnimated:YES completionHandler:nil]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) @@ -420,9 +599,15 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath buttonTitles:@[@"Button 1", @"Button 2"] cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" - actionHandler:nil - cancelHandler:nil - destructiveHandler:nil]; + actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { + NSLog(@"actionHandler, %@, %lu", title, (long unsigned)index); + } + cancelHandler:^(LGAlertView *alertView) { + NSLog(@"cancelHandler"); + } + destructiveHandler:^(LGAlertView *alertView) { + NSLog(@"destructiveHandler"); + }]; [alertView1 transitionToAlertView:alertView2 completionHandler:nil]; }); diff --git a/Demo/Podfile.lock b/Demo/Podfile.lock index 4dcda5b..d3756e2 100644 --- a/Demo/Podfile.lock +++ b/Demo/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - LGAlertView (2.0.2) + - LGAlertView (2.0.4) DEPENDENCIES: - LGAlertView (from `../`) @@ -9,6 +9,6 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - LGAlertView: 044299d2a66674a13c04d397555ffc5e4a666831 + LGAlertView: bd8c89da95f31a9bdeda279d9939629cbcbfaaca COCOAPODS: 0.39.0 diff --git a/LGAlertView.podspec b/LGAlertView.podspec index ba953ac..b786f59 100644 --- a/LGAlertView.podspec +++ b/LGAlertView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'LGAlertView' - s.version = '2.0.3' + s.version = '2.0.4' s.platform = :ios, '6.0' s.license = 'MIT' s.homepage = 'https://github.com/Friend-LGA/LGAlertView' diff --git a/LGAlertView/LGAlertView.h b/LGAlertView/LGAlertView.h index 010b4bb..57f3484 100644 --- a/LGAlertView/LGAlertView.h +++ b/LGAlertView/LGAlertView.h @@ -28,6 +28,7 @@ // #import +#import "LGAlertViewButtonProperties.h" @class LGAlertView; @@ -55,19 +56,17 @@ static NSString *const kLGAlertViewDestructiveNotification = @"LGAlertViewDestru @interface LGAlertView : NSObject -typedef enum +typedef NS_ENUM(NSUInteger, LGAlertViewStyle) { LGAlertViewStyleAlert = 0, LGAlertViewStyleActionSheet = 1 -} -LGAlertViewStyle; +}; -typedef enum +typedef NS_ENUM(NSUInteger, LGAlertViewWindowLevel) { LGAlertViewWindowLevelAboveStatusBar = 0, LGAlertViewWindowLevelBelowStatusBar = 1 -} -LGAlertViewWindowLevel; +}; @property (assign, nonatomic, getter=isShowing) BOOL showing; /** Default is LGAlertViewWindowLevelAboveStatusBar */ @@ -119,28 +118,35 @@ LGAlertViewWindowLevel; @property (assign, nonatomic) NSLineBreakMode buttonsLineBreakMode; @property (assign, nonatomic) CGFloat buttonsMinimumScaleFactor; @property (assign, nonatomic, getter=isButtonsAdjustsFontSizeToFitWidth) BOOL buttonsAdjustsFontSizeToFitWidth; +@property (assign, nonatomic, getter=isCancelButtonEnabled) BOOL buttonsEnabled; @property (strong, nonatomic) UIColor *cancelButtonTitleColor; @property (strong, nonatomic) UIColor *cancelButtonTitleColorHighlighted; +@property (strong, nonatomic) UIColor *cancelButtonTitleColorDisabled; @property (assign, nonatomic) NSTextAlignment cancelButtonTextAlignment; @property (strong, nonatomic) UIFont *cancelButtonFont; @property (strong, nonatomic) UIColor *cancelButtonBackgroundColor; @property (strong, nonatomic) UIColor *cancelButtonBackgroundColorHighlighted; +@property (strong, nonatomic) UIColor *cancelButtonBackgroundColorDisabled; @property (assign, nonatomic) NSUInteger cancelButtonNumberOfLines; @property (assign, nonatomic) NSLineBreakMode cancelButtonLineBreakMode; @property (assign, nonatomic) CGFloat cancelButtonMinimumScaleFactor; @property (assign, nonatomic, getter=isCancelButtonAdjustsFontSizeToFitWidth) BOOL cancelButtonAdjustsFontSizeToFitWidth; +@property (assign, nonatomic, getter=isCancelButtonEnabled) BOOL cancelButtonEnabled; @property (strong, nonatomic) UIColor *destructiveButtonTitleColor; @property (strong, nonatomic) UIColor *destructiveButtonTitleColorHighlighted; +@property (strong, nonatomic) UIColor *destructiveButtonTitleColorDisabled; @property (assign, nonatomic) NSTextAlignment destructiveButtonTextAlignment; @property (strong, nonatomic) UIFont *destructiveButtonFont; @property (strong, nonatomic) UIColor *destructiveButtonBackgroundColor; @property (strong, nonatomic) UIColor *destructiveButtonBackgroundColorHighlighted; +@property (strong, nonatomic) UIColor *destructiveButtonBackgroundColorDisabled; @property (assign, nonatomic) NSUInteger destructiveButtonNumberOfLines; @property (assign, nonatomic) NSLineBreakMode destructiveButtonLineBreakMode; @property (assign, nonatomic) CGFloat destructiveButtonMinimumScaleFactor; @property (assign, nonatomic, getter=isDestructiveButtonAdjustsFontSizeToFitWidth) BOOL destructiveButtonAdjustsFontSizeToFitWidth; +@property (assign, nonatomic, getter=isDestructiveButtonEnabled) BOOL destructiveButtonEnabled; @property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle; @property (strong, nonatomic) UIColor *activityIndicatorViewColor; @@ -477,6 +483,8 @@ LGAlertViewWindowLevel; - (void)setProgress:(float)progress progressLabelText:(NSString *)progressLabelText; +- (void)setButtonPropertiesAtIndex:(NSUInteger)index handler:(void(^)(LGAlertViewButtonProperties *properties))handler; + - (void)setButtonAtIndex:(NSUInteger)index enabled:(BOOL)enabled; - (BOOL)isButtonEnabledAtIndex:(NSUInteger)index; @@ -487,6 +495,7 @@ LGAlertViewWindowLevel; - (void)forceActionAtIndex:(NSUInteger)index; + (void)setTintColor:(UIColor *)color; ++ (void)setColorful:(BOOL)colorful; #pragma mark - diff --git a/LGAlertView/LGAlertView.m b/LGAlertView/LGAlertView.m index bb522b0..72672b0 100644 --- a/LGAlertView/LGAlertView.m +++ b/LGAlertView/LGAlertView.m @@ -51,6 +51,7 @@ static NSMutableArray *kLGAlertViewWindowsArray; static UIColor *kLGAlertViewTintColor; +static BOOL kLGAlertViewColorful = YES; #pragma mark - Interface @@ -120,8 +121,6 @@ @interface LGAlertView () index) { - if (_destructiveButtonTitle.length) - index++; + _buttonsEnabledArray[index] = [NSNumber numberWithBool:enabled]; - if (enabled) - _disabledButtonIndex = -1; - else - _disabledButtonIndex = index; + if (_tableView) + { + if (_destructiveButtonTitle.length) + index++; - LGAlertViewCell *cell = (LGAlertViewCell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]]; - cell.enabled = enabled; - } - else - { - if (enabled) - _disabledButtonIndex = -1; + LGAlertViewCell *cell = (LGAlertViewCell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]]; + cell.enabled = enabled; + } 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; + 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 + return _buttonsEnabledArray[index]; +} + +- (void)setButtonPropertiesAtIndex:(NSUInteger)index + handler:(void(^)(LGAlertViewButtonProperties *properties))handler; +{ + if (handler && _buttonTitles.count > index) { - if (_tableView) index++; + if (!_buttonsPropertiesDictionary) + _buttonsPropertiesDictionary = [NSMutableDictionary new]; + + for (NSUInteger index=0; index<_buttonTitles.count; index++) + { + LGAlertViewButtonProperties *properties = [LGAlertViewButtonProperties new]; - return !(index == _disabledButtonIndex); + handler(properties); + + if (properties.isUserEnabled) + _buttonsEnabledArray[index] = [NSNumber numberWithBool:properties.enabled]; + + [_buttonsPropertiesDictionary setObject:properties forKey:[NSNumber numberWithInteger:index]]; + } } } @@ -1365,8 +1407,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N { cell.titleColor = _destructiveButtonTitleColor; cell.titleColorHighlighted = _destructiveButtonTitleColorHighlighted; + cell.titleColorDisabled = _destructiveButtonTitleColorDisabled; cell.backgroundColorNormal = _destructiveButtonBackgroundColor; cell.backgroundColorHighlighted = _destructiveButtonBackgroundColorHighlighted; + cell.backgroundColorDisabled = _destructiveButtonBackgroundColorDisabled; cell.separatorVisible = (indexPath.row != _buttonTitles.count-1); cell.separatorColor_ = _separatorsColor; cell.textAlignment = _destructiveButtonTextAlignment; @@ -1375,13 +1419,16 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.lineBreakMode = _destructiveButtonLineBreakMode; cell.adjustsFontSizeToFitWidth = _destructiveButtonAdjustsFontSizeToFitWidth; cell.minimumScaleFactor = _destructiveButtonMinimumScaleFactor; + cell.enabled = _destructiveButtonEnabled; } else if (_cancelButtonTitle.length && !kLGAlertViewIsCancelButtonSeparate(self) && indexPath.row == _buttonTitles.count-1) { cell.titleColor = _cancelButtonTitleColor; cell.titleColorHighlighted = _cancelButtonTitleColorHighlighted; + cell.titleColorDisabled = _cancelButtonTitleColorDisabled; cell.backgroundColorNormal = _cancelButtonBackgroundColor; cell.backgroundColorHighlighted = _cancelButtonBackgroundColorHighlighted; + cell.backgroundColorDisabled = _cancelButtonBackgroundColorDisabled; cell.separatorVisible = NO; cell.separatorColor_ = _separatorsColor; cell.textAlignment = _cancelButtonTextAlignment; @@ -1390,24 +1437,29 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.lineBreakMode = _cancelButtonLineBreakMode; cell.adjustsFontSizeToFitWidth = _cancelButtonAdjustsFontSizeToFitWidth; cell.minimumScaleFactor = _cancelButtonMinimumScaleFactor; + cell.enabled = _cancelButtonEnabled; } else { - cell.titleColor = _buttonsTitleColor; - cell.titleColorHighlighted = _buttonsTitleColorHighlighted; - cell.titleColorDisabled = _buttonsTitleColorDisabled; - cell.backgroundColorNormal = _buttonsBackgroundColor; - cell.backgroundColorHighlighted = _buttonsBackgroundColorHighlighted; - cell.backgroundColorDisabled = _buttonsBackgroundColorDisabled; + LGAlertViewButtonProperties *properties = nil; + if (_buttonsPropertiesDictionary) + properties = _buttonsPropertiesDictionary[[NSNumber numberWithInteger:(indexPath.row - (_destructiveButtonTitle.length ? 1 : 0))]]; + + cell.titleColor = (properties.isUserTitleColor ? properties.titleColor : _buttonsTitleColor); + cell.titleColorHighlighted = (properties.isUserTitleColorHighlighted ? properties.titleColorHighlighted : _buttonsTitleColorHighlighted); + cell.titleColorDisabled = (properties.isUserTitleColorDisabled ? properties.titleColorDisabled : _buttonsTitleColorDisabled); + cell.backgroundColorNormal = (properties.isUserBackgroundColor ? properties.backgroundColor : _buttonsBackgroundColor); + cell.backgroundColorHighlighted = (properties.isUserBackgroundColorHighlighted ? properties.backgroundColorHighlighted : _buttonsBackgroundColorHighlighted); + cell.backgroundColorDisabled = (properties.isUserBackgroundColorDisabled ? properties.backgroundColorDisabled : _buttonsBackgroundColorDisabled); cell.separatorVisible = (indexPath.row != _buttonTitles.count-1); cell.separatorColor_ = _separatorsColor; - cell.textAlignment = _buttonsTextAlignment; - cell.font = _buttonsFont; - cell.numberOfLines = _buttonsNumberOfLines; - cell.lineBreakMode = _buttonsLineBreakMode; - cell.adjustsFontSizeToFitWidth = _buttonsAdjustsFontSizeToFitWidth; - cell.minimumScaleFactor = _buttonsMinimumScaleFactor; - cell.enabled = !(indexPath.row == _disabledButtonIndex); + cell.textAlignment = (properties.isUserTextAlignment ? properties.textAlignment : _buttonsTextAlignment); + cell.font = (properties.isUserFont ? properties.font : _buttonsFont); + cell.numberOfLines = (properties.isUserNumberOfLines ? properties.numberOfLines : _buttonsNumberOfLines); + cell.lineBreakMode = (properties.isUserLineBreakMode ? properties.lineBreakMode : _buttonsLineBreakMode); + cell.adjustsFontSizeToFitWidth = (properties.isUserAdjustsFontSizeTofitWidth ? properties.adjustsFontSizeToFitWidth : _buttonsAdjustsFontSizeToFitWidth); + cell.minimumScaleFactor = (properties.isUserMinimimScaleFactor ? properties.minimumScaleFactor : _buttonsMinimumScaleFactor); + cell.enabled = _buttonsEnabledArray[indexPath.row - (_destructiveButtonTitle.length ? 1 : 0)]; } return cell; @@ -1518,7 +1570,7 @@ - (void)showAnimated:(BOOL)animated hidden:(BOOL)hidden completionHandler:(void( if (self.isShowing) return; _window.windowLevel = UIWindowLevelStatusBar + (_windowLevel == LGAlertViewWindowLevelAboveStatusBar ? 1 : -1); - _window.userInteractionEnabled = NO; + _view.userInteractionEnabled = NO; CGSize size = _viewController.view.bounds.size; @@ -1661,14 +1713,14 @@ - (void)showComplete // ----- - _window.userInteractionEnabled = YES; + _view.userInteractionEnabled = YES; } - (void)dismissAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler { if (!self.isShowing) return; - _window.userInteractionEnabled = NO; + _view.userInteractionEnabled = NO; _showing = NO; @@ -1769,12 +1821,15 @@ - (void)dismissComplete - (void)transitionToAlertView:(LGAlertView *)alertView completionHandler:(void(^)())completionHandler { - self.window.userInteractionEnabled = NO; + _view.userInteractionEnabled = NO; [alertView showAnimated:NO hidden:YES completionHandler:^(void) { NSTimeInterval duration = 0.3; + BOOL cancelButtonSelf = kLGAlertViewIsCancelButtonSeparate(self) && _cancelButtonTitle.length; + BOOL cancelButtonNext = kLGAlertViewIsCancelButtonSeparate(alertView) && alertView.cancelButtonTitle.length; + // ----- [UIView animateWithDuration:duration @@ -1782,11 +1837,11 @@ - (void)transitionToAlertView:(LGAlertView *)alertView completionHandler:(void(^ { _scrollView.alpha = 0.f; - if (kLGAlertViewIsCancelButtonSeparate(self)) + if (cancelButtonSelf) { _cancelButton.alpha = 0.f; - if (!kLGAlertViewIsCancelButtonSeparate(alertView)) + if (!cancelButtonNext) _styleCancelView.alpha = 0.f; } } @@ -1811,13 +1866,23 @@ - (void)transitionToAlertView:(LGAlertView *)alertView completionHandler:(void(^ alertView.styleView.hidden = NO; _styleView.hidden = YES; - if (kLGAlertViewIsCancelButtonSeparate(self) && - kLGAlertViewIsCancelButtonSeparate(alertView)) + // ----- + + if (cancelButtonNext) { alertView.styleCancelView.hidden = NO; - _styleCancelView.hidden = YES; + + if (!cancelButtonSelf) + alertView.styleCancelView.alpha = 0.f; } + // ----- + + if (cancelButtonSelf && cancelButtonNext) + _styleCancelView.hidden = YES; + + // ----- + [UIView animateWithDuration:duration animations:^(void) { @@ -1828,13 +1893,10 @@ - (void)transitionToAlertView:(LGAlertView *)alertView completionHandler:(void(^ alertView.scrollView.alpha = 0.f; alertView.scrollView.hidden = NO; - if (kLGAlertViewIsCancelButtonSeparate(alertView)) + if (cancelButtonNext) { alertView.cancelButton.alpha = 0.f; alertView.cancelButton.hidden = NO; - - if (!kLGAlertViewIsCancelButtonSeparate(self)) - alertView.styleCancelView.alpha = 0.f; } [UIView animateWithDuration:duration @@ -1843,11 +1905,11 @@ - (void)transitionToAlertView:(LGAlertView *)alertView completionHandler:(void(^ _scrollView.alpha = 0.f; alertView.scrollView.alpha = 1.f; - if (kLGAlertViewIsCancelButtonSeparate(alertView)) + if (cancelButtonNext) { alertView.cancelButton.alpha = 1.f; - if (!kLGAlertViewIsCancelButtonSeparate(self)) + if (!cancelButtonSelf) alertView.styleCancelView.alpha = 1.f; } } @@ -2122,9 +2184,11 @@ - (void)subviewsInvalidateWithSize:(CGSize)size [_destructiveButton setTitleColor:_destructiveButtonTitleColor forState:UIControlStateNormal]; [_destructiveButton setTitleColor:_destructiveButtonTitleColorHighlighted forState:UIControlStateHighlighted]; [_destructiveButton setTitleColor:_destructiveButtonTitleColorHighlighted forState:UIControlStateSelected]; + [_destructiveButton setTitleColor:_destructiveButtonTitleColorDisabled forState:UIControlStateDisabled]; [_destructiveButton setBackgroundImage:[LGAlertView image1x1WithColor:_destructiveButtonBackgroundColor] forState:UIControlStateNormal]; [_destructiveButton setBackgroundImage:[LGAlertView image1x1WithColor:_destructiveButtonBackgroundColorHighlighted] forState:UIControlStateHighlighted]; [_destructiveButton setBackgroundImage:[LGAlertView image1x1WithColor:_destructiveButtonBackgroundColorHighlighted] forState:UIControlStateSelected]; + [_destructiveButton setBackgroundImage:[LGAlertView image1x1WithColor:_destructiveButtonBackgroundColorDisabled] forState:UIControlStateDisabled]; _destructiveButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW); _destructiveButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; if (_destructiveButtonTextAlignment == NSTextAlignmentCenter) @@ -2133,6 +2197,7 @@ - (void)subviewsInvalidateWithSize:(CGSize)size _destructiveButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; else if (_destructiveButtonTextAlignment == NSTextAlignmentRight) _destructiveButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; + _destructiveButton.enabled = _destructiveButtonEnabled; [_destructiveButton addTarget:self action:@selector(destructiveAction:) forControlEvents:UIControlEventTouchUpInside]; CGSize size = [_destructiveButton sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; @@ -2153,31 +2218,36 @@ - (void)subviewsInvalidateWithSize:(CGSize)size if (_buttonTitles.count > 0 && !showTable) { + LGAlertViewButtonProperties *properties = nil; + if (_buttonsPropertiesDictionary) + properties = _buttonsPropertiesDictionary[[NSNumber numberWithInteger:0]]; + _firstButton = [UIButton new]; _firstButton.backgroundColor = [UIColor clearColor]; - _firstButton.titleLabel.numberOfLines = _buttonsNumberOfLines; - _firstButton.titleLabel.lineBreakMode = _buttonsLineBreakMode; - _firstButton.titleLabel.adjustsFontSizeToFitWidth = _buttonsAdjustsFontSizeToFitWidth; - _firstButton.titleLabel.minimumScaleFactor = _buttonsMinimumScaleFactor; - _firstButton.titleLabel.font = _buttonsFont; + _firstButton.titleLabel.numberOfLines = (properties.isUserNumberOfLines ? properties.numberOfLines : _buttonsNumberOfLines); + _firstButton.titleLabel.lineBreakMode = (properties.isUserLineBreakMode ? properties.lineBreakMode : _buttonsLineBreakMode); + _firstButton.titleLabel.adjustsFontSizeToFitWidth = (properties.isAdjustsFontSizeToFitWidth ? properties.adjustsFontSizeToFitWidth : _buttonsAdjustsFontSizeToFitWidth); + _firstButton.titleLabel.minimumScaleFactor = (properties.isUserMinimimScaleFactor ? properties.minimumScaleFactor : _buttonsMinimumScaleFactor); + _firstButton.titleLabel.font = (properties.isUserFont ? properties.font : _buttonsFont); [_firstButton setTitle:_buttonTitles[0] forState:UIControlStateNormal]; - [_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 setTitleColor:(properties.isUserTitleColor ? properties.titleColor : _buttonsTitleColor) forState:UIControlStateNormal]; + [_firstButton setTitleColor:(properties.isUserTitleColorHighlighted ? properties.titleColorHighlighted : _buttonsTitleColorHighlighted) forState:UIControlStateHighlighted]; + [_firstButton setTitleColor:(properties.isUserTitleColorHighlighted ? properties.titleColorHighlighted : _buttonsTitleColorHighlighted) forState:UIControlStateSelected]; + [_firstButton setTitleColor:(properties.isUserTitleColorDisabled ? properties.titleColorDisabled : _buttonsTitleColorDisabled) forState:UIControlStateDisabled]; + [_firstButton setBackgroundImage:[LGAlertView image1x1WithColor:(properties.isUserBackgroundColor ? properties.backgroundColor : _buttonsBackgroundColor)] forState:UIControlStateNormal]; + [_firstButton setBackgroundImage:[LGAlertView image1x1WithColor:(properties.isUserBackgroundColorHighlighted ? properties.backgroundColorHighlighted : _buttonsBackgroundColorHighlighted)] forState:UIControlStateHighlighted]; + [_firstButton setBackgroundImage:[LGAlertView image1x1WithColor:(properties.isUserBackgroundColorHighlighted ? properties.backgroundColorHighlighted : _buttonsBackgroundColorHighlighted)] forState:UIControlStateSelected]; + [_firstButton setBackgroundImage:[LGAlertView image1x1WithColor:(properties.isUserBackgroundColorDisabled ? properties.backgroundColorDisabled : _buttonsBackgroundColorDisabled)] forState:UIControlStateDisabled]; _firstButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW); _firstButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - if (_buttonsTextAlignment == NSTextAlignmentCenter) + NSTextAlignment textAlignment = (properties.isUserTextAlignment ? properties.textAlignment : _buttonsTextAlignment); + if (textAlignment == NSTextAlignmentCenter) _firstButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; - else if (_buttonsTextAlignment == NSTextAlignmentLeft) + else if (textAlignment == NSTextAlignmentLeft) _firstButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; - else if (_buttonsTextAlignment == NSTextAlignmentRight) + else if (textAlignment == NSTextAlignmentRight) _firstButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; - _firstButton.enabled = (_disabledButtonIndex != 0); + _firstButton.enabled = _buttonsEnabledArray[0]; [_firstButton addTarget:self action:@selector(firstButtonAction:) forControlEvents:UIControlEventTouchUpInside]; CGSize size = [_firstButton sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; @@ -2187,31 +2257,36 @@ - (void)subviewsInvalidateWithSize:(CGSize)size if (_buttonTitles.count > 1 && !showTable) { + LGAlertViewButtonProperties *properties = nil; + if (_buttonsPropertiesDictionary) + properties = _buttonsPropertiesDictionary[[NSNumber numberWithInteger:1]]; + _secondButton = [UIButton new]; _secondButton.backgroundColor = [UIColor clearColor]; - _secondButton.titleLabel.numberOfLines = _buttonsNumberOfLines; - _secondButton.titleLabel.lineBreakMode = _buttonsLineBreakMode; - _secondButton.titleLabel.adjustsFontSizeToFitWidth = _buttonsAdjustsFontSizeToFitWidth; - _secondButton.titleLabel.minimumScaleFactor = _buttonsMinimumScaleFactor; - _secondButton.titleLabel.font = _buttonsFont; + _secondButton.titleLabel.numberOfLines = (properties.isUserNumberOfLines ? properties.numberOfLines : _buttonsNumberOfLines); + _secondButton.titleLabel.lineBreakMode = (properties.isUserLineBreakMode ? properties.lineBreakMode : _buttonsLineBreakMode); + _secondButton.titleLabel.adjustsFontSizeToFitWidth = (properties.isAdjustsFontSizeToFitWidth ? properties.adjustsFontSizeToFitWidth : _buttonsAdjustsFontSizeToFitWidth); + _secondButton.titleLabel.minimumScaleFactor = (properties.isUserMinimimScaleFactor ? properties.minimumScaleFactor : _buttonsMinimumScaleFactor); + _secondButton.titleLabel.font = (properties.isUserFont ? properties.font : _buttonsFont); [_secondButton setTitle:_buttonTitles[1] forState:UIControlStateNormal]; - [_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 setTitleColor:(properties.isUserTitleColor ? properties.titleColor : _buttonsTitleColor) forState:UIControlStateNormal]; + [_secondButton setTitleColor:(properties.isUserTitleColorHighlighted ? properties.titleColorHighlighted : _buttonsTitleColorHighlighted) forState:UIControlStateHighlighted]; + [_secondButton setTitleColor:(properties.isUserTitleColorHighlighted ? properties.titleColorHighlighted : _buttonsTitleColorHighlighted) forState:UIControlStateSelected]; + [_secondButton setTitleColor:(properties.isUserTitleColorDisabled ? properties.titleColorDisabled : _buttonsTitleColorDisabled) forState:UIControlStateDisabled]; + [_secondButton setBackgroundImage:[LGAlertView image1x1WithColor:(properties.isUserBackgroundColor ? properties.backgroundColor : _buttonsBackgroundColor)] forState:UIControlStateNormal]; + [_secondButton setBackgroundImage:[LGAlertView image1x1WithColor:(properties.isUserBackgroundColorHighlighted ? properties.backgroundColorHighlighted : _buttonsBackgroundColorHighlighted)] forState:UIControlStateHighlighted]; + [_secondButton setBackgroundImage:[LGAlertView image1x1WithColor:(properties.isUserBackgroundColorHighlighted ? properties.backgroundColorHighlighted : _buttonsBackgroundColorHighlighted)] forState:UIControlStateSelected]; + [_secondButton setBackgroundImage:[LGAlertView image1x1WithColor:(properties.isUserBackgroundColorDisabled ? properties.backgroundColorDisabled : _buttonsBackgroundColorDisabled)] forState:UIControlStateDisabled]; _secondButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW); _secondButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - if (_buttonsTextAlignment == NSTextAlignmentCenter) + NSTextAlignment textAlignment = (properties.isUserTextAlignment ? properties.textAlignment : _buttonsTextAlignment); + if (textAlignment == NSTextAlignmentCenter) _secondButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; - else if (_buttonsTextAlignment == NSTextAlignmentLeft) + else if (textAlignment == NSTextAlignmentLeft) _secondButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; - else if (_buttonsTextAlignment == NSTextAlignmentRight) + else if (textAlignment == NSTextAlignmentRight) _secondButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; - _secondButton.enabled = (_disabledButtonIndex != 1); + _secondButton.enabled = _buttonsEnabledArray[1]; [_secondButton addTarget:self action:@selector(secondButtonAction:) forControlEvents:UIControlEventTouchUpInside]; CGSize size = [_secondButton sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; @@ -2221,32 +2296,37 @@ - (void)subviewsInvalidateWithSize:(CGSize)size if (_buttonTitles.count > 2 && !showTable) { + LGAlertViewButtonProperties *properties = nil; + if (_buttonsPropertiesDictionary) + properties = _buttonsPropertiesDictionary[[NSNumber numberWithInteger:2]]; + _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.titleLabel.numberOfLines = (properties.isUserNumberOfLines ? properties.numberOfLines : _buttonsNumberOfLines); + _thirdButton.titleLabel.lineBreakMode = (properties.isUserLineBreakMode ? properties.lineBreakMode : _buttonsLineBreakMode); + _thirdButton.titleLabel.adjustsFontSizeToFitWidth = (properties.isAdjustsFontSizeToFitWidth ? properties.adjustsFontSizeToFitWidth : _buttonsAdjustsFontSizeToFitWidth); + _thirdButton.titleLabel.minimumScaleFactor = (properties.isUserMinimimScaleFactor ? properties.minimumScaleFactor : _buttonsMinimumScaleFactor); + _thirdButton.titleLabel.font = (properties.isUserFont ? properties.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 setTitleColor:(properties.isUserTitleColor ? properties.titleColor : _buttonsTitleColor) forState:UIControlStateNormal]; + [_thirdButton setTitleColor:(properties.isUserTitleColorHighlighted ? properties.titleColorHighlighted : _buttonsTitleColorHighlighted) forState:UIControlStateHighlighted]; + [_thirdButton setTitleColor:(properties.isUserTitleColorHighlighted ? properties.titleColorHighlighted : _buttonsTitleColorHighlighted) forState:UIControlStateSelected]; + [_thirdButton setTitleColor:(properties.isUserTitleColorDisabled ? properties.titleColorDisabled : _buttonsTitleColorDisabled) forState:UIControlStateDisabled]; + [_thirdButton setBackgroundImage:[LGAlertView image1x1WithColor:(properties.isUserBackgroundColor ? properties.backgroundColor : _buttonsBackgroundColor)] forState:UIControlStateNormal]; + [_thirdButton setBackgroundImage:[LGAlertView image1x1WithColor:(properties.isUserBackgroundColorHighlighted ? properties.backgroundColorHighlighted : _buttonsBackgroundColorHighlighted)] forState:UIControlStateHighlighted]; + [_thirdButton setBackgroundImage:[LGAlertView image1x1WithColor:(properties.isUserBackgroundColorHighlighted ? properties.backgroundColorHighlighted : _buttonsBackgroundColorHighlighted)] forState:UIControlStateSelected]; + [_thirdButton setBackgroundImage:[LGAlertView image1x1WithColor:(properties.isUserBackgroundColorDisabled ? properties.backgroundColorDisabled : _buttonsBackgroundColorDisabled)] forState:UIControlStateDisabled]; _thirdButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW); _thirdButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; - if (_buttonsTextAlignment == NSTextAlignmentCenter) + NSTextAlignment textAlignment = (properties.isUserTextAlignment ? properties.textAlignment : _buttonsTextAlignment); + if (textAlignment == NSTextAlignmentCenter) _thirdButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; - else if (_buttonsTextAlignment == NSTextAlignmentLeft) + else if (textAlignment == NSTextAlignmentLeft) _thirdButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; - else if (_buttonsTextAlignment == NSTextAlignmentRight) + else if (textAlignment == NSTextAlignmentRight) _thirdButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; - _thirdButton.enabled = (_disabledButtonIndex != 2); - [_thirdButton addTarget:self action:@selector(secondButtonAction:) forControlEvents:UIControlEventTouchUpInside]; + _thirdButton.enabled = _buttonsEnabledArray[2]; + [_thirdButton addTarget:self action:@selector(thirdButtonAction:) forControlEvents:UIControlEventTouchUpInside]; CGSize size = [_thirdButton sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; @@ -2594,9 +2674,11 @@ - (void)cancelButtonInit [_cancelButton setTitleColor:_cancelButtonTitleColor forState:UIControlStateNormal]; [_cancelButton setTitleColor:_cancelButtonTitleColorHighlighted forState:UIControlStateHighlighted]; [_cancelButton setTitleColor:_cancelButtonTitleColorHighlighted forState:UIControlStateSelected]; + [_cancelButton setTitleColor:_cancelButtonTitleColorDisabled forState:UIControlStateDisabled]; [_cancelButton setBackgroundImage:[LGAlertView image1x1WithColor:_cancelButtonBackgroundColor] forState:UIControlStateNormal]; [_cancelButton setBackgroundImage:[LGAlertView image1x1WithColor:_cancelButtonBackgroundColorHighlighted] forState:UIControlStateHighlighted]; [_cancelButton setBackgroundImage:[LGAlertView image1x1WithColor:_cancelButtonBackgroundColorHighlighted] forState:UIControlStateSelected]; + [_cancelButton setBackgroundImage:[LGAlertView image1x1WithColor:_cancelButtonBackgroundColorDisabled] forState:UIControlStateDisabled]; _cancelButton.contentEdgeInsets = UIEdgeInsetsMake(kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW, kLGAlertViewButtonTitleMarginH, kLGAlertViewPaddingW); _cancelButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; if (_cancelButtonTextAlignment == NSTextAlignmentCenter) @@ -2605,6 +2687,7 @@ - (void)cancelButtonInit _cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; else if (_cancelButtonTextAlignment == NSTextAlignmentRight) _cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; + _cancelButton.enabled = _cancelButtonEnabled; [_cancelButton addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside]; } diff --git a/LGAlertView/LGAlertViewButtonProperties.h b/LGAlertView/LGAlertViewButtonProperties.h new file mode 100644 index 0000000..fd64c38 --- /dev/null +++ b/LGAlertView/LGAlertViewButtonProperties.h @@ -0,0 +1,41 @@ +// +// LGAlertViewButtonProperties.h +// Pods +// +// Created by Grigory Lutkov on 09.11.15. +// +// + +#import + +@interface LGAlertViewButtonProperties : NSObject + +@property (strong, nonatomic) UIColor *titleColor; +@property (strong, nonatomic) UIColor *titleColorHighlighted; +@property (strong, nonatomic) UIColor *titleColorDisabled; +@property (assign, nonatomic) NSTextAlignment textAlignment; +@property (strong, nonatomic) UIFont *font; +@property (strong, nonatomic) UIColor *backgroundColor; +@property (strong, nonatomic) UIColor *backgroundColorHighlighted; +@property (strong, nonatomic) UIColor *backgroundColorDisabled; +@property (assign, nonatomic) NSUInteger numberOfLines; +@property (assign, nonatomic) NSLineBreakMode lineBreakMode; +@property (assign, nonatomic) CGFloat minimumScaleFactor; +@property (assign, nonatomic, getter=isAdjustsFontSizeToFitWidth) BOOL adjustsFontSizeToFitWidth; +@property (assign, nonatomic, getter=isEnabled) BOOL enabled; + +@property (assign, nonatomic, readonly, getter=isUserTitleColor) BOOL userTitleColor; +@property (assign, nonatomic, readonly, getter=isUserTitleColorHighlighted) BOOL userTitleColorHighlighted; +@property (assign, nonatomic, readonly, getter=isUserTitleColorDisabled) BOOL userTitleColorDisabled; +@property (assign, nonatomic, readonly, getter=isUserTextAlignment) BOOL userTextAlignment; +@property (assign, nonatomic, readonly, getter=isUserFont) BOOL userFont; +@property (assign, nonatomic, readonly, getter=isUserBackgroundColor) BOOL userBackgroundColor; +@property (assign, nonatomic, readonly, getter=isUserBackgroundColorHighlighted) BOOL userBackgroundColorHighlighted; +@property (assign, nonatomic, readonly, getter=isUserBackgroundColorDisabled) BOOL userBackgroundColorDisabled; +@property (assign, nonatomic, readonly, getter=isUserNumberOfLines) BOOL userNumberOfLines; +@property (assign, nonatomic, readonly, getter=isUserLineBreakMode) BOOL userLineBreakMode; +@property (assign, nonatomic, readonly, getter=isUserMinimimScaleFactor) BOOL userMinimumScaleFactor; +@property (assign, nonatomic, readonly, getter=isUserAdjustsFontSizeTofitWidth) BOOL userAdjustsFontSizeTofitWidth; +@property (assign, nonatomic, readonly, getter=isUserEnabled) BOOL userEnabled; + +@end diff --git a/LGAlertView/LGAlertViewButtonProperties.m b/LGAlertView/LGAlertViewButtonProperties.m new file mode 100644 index 0000000..033acd5 --- /dev/null +++ b/LGAlertView/LGAlertViewButtonProperties.m @@ -0,0 +1,133 @@ +// +// LGAlertViewButtonProperties.m +// Pods +// +// Created by Grigory Lutkov on 09.11.15. +// +// + +#import "LGAlertViewButtonProperties.h" + +@implementation LGAlertViewButtonProperties + +- (id)initWithCoder:(NSCoder *)coder +{ + self = [super init]; + if (self) + { + _titleColor = [coder decodeObjectForKey:@"titleColor"]; + _titleColorHighlighted = [coder decodeObjectForKey:@"titleColorHighlighted"]; + _titleColorDisabled = [coder decodeObjectForKey:@"titleColorDisabled"]; + _font = [coder decodeObjectForKey:@"font"]; + _backgroundColor = [coder decodeObjectForKey:@"backgroundColor"]; + _backgroundColorHighlighted = [coder decodeObjectForKey:@"backgroundColorHighlighted"]; + _backgroundColorDisabled = [coder decodeObjectForKey:@"backgroundColorDisabled"]; + } + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [coder encodeObject:_titleColor forKey:@"titleColor"]; + [coder encodeObject:_titleColorHighlighted forKey:@"titleColorHighlighted"]; + [coder encodeObject:_titleColorDisabled forKey:@"titleColorDisabled"]; + [coder encodeObject:_font forKey:@"font"]; + [coder encodeObject:_backgroundColor forKey:@"backgroundColor"]; + [coder encodeObject:_backgroundColorHighlighted forKey:@"backgroundColorHighlighted"]; + [coder encodeObject:_backgroundColorDisabled forKey:@"backgroundColorDisabled"]; +} + +#pragma mark - + +- (void)setTitleColor:(UIColor *)titleColor +{ + _titleColor = titleColor; + + _userTitleColor = YES; +} + +- (void)setTitleColorHighlighted:(UIColor *)titleColorHighlighted +{ + _titleColorHighlighted = titleColorHighlighted; + + _userTitleColorHighlighted = YES; +} + +- (void)setTitleColorDisabled:(UIColor *)titleColorDisabled +{ + _titleColorDisabled = titleColorDisabled; + + _userTitleColorDisabled = YES; +} + +- (void)setTextAlignment:(NSTextAlignment)textAlignment +{ + _textAlignment = textAlignment; + + _userTextAlignment = YES; +} + +- (void)setFont:(UIFont *)font +{ + _font = font; + + _userFont = YES; +} + +- (void)setBackgroundColor:(UIColor *)backgroundColor +{ + _backgroundColor = backgroundColor; + + _userBackgroundColor = YES; +} + +- (void)setBackgroundColorHighlighted:(UIColor *)backgroundColorHighlighted +{ + _backgroundColorHighlighted = backgroundColorHighlighted; + + _userBackgroundColorHighlighted = YES; +} + +- (void)setBackgroundColorDisabled:(UIColor *)backgroundColorDisabled +{ + _backgroundColorDisabled = backgroundColorDisabled; + + _userBackgroundColorDisabled = YES; +} + +- (void)setNumberOfLines:(NSUInteger)numberOfLines +{ + _numberOfLines = numberOfLines; + + _userNumberOfLines = YES; +} + +- (void)setLineBreakMode:(NSLineBreakMode)lineBreakMode +{ + _lineBreakMode = lineBreakMode; + + _userLineBreakMode = YES; +} + +- (void)setMinimumScaleFactor:(CGFloat)minimumScaleFactor +{ + _minimumScaleFactor = minimumScaleFactor; + + _userMinimumScaleFactor = YES; +} + +- (void)setAdjustsFontSizeToFitWidth:(BOOL)adjustsFontSizeToFitWidth +{ + _adjustsFontSizeToFitWidth = adjustsFontSizeToFitWidth; + + _userAdjustsFontSizeTofitWidth = YES; +} + +- (void)setEnabled:(BOOL)enabled +{ + _enabled = enabled; + + _userEnabled = YES; +} + +@end