Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show a space below actions in UIAlertController

Versions of iOS prior to 8 allowed me to create a UIActionsheet which would show a group of buttons, some space, and then a cancel button. Something like this:

Desired Behavior

However in iOS 8 when I try and create the same look I end up with something that looks like this:

iOS 8 Behavior

The code, in iOS 8 looks like this:

UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

[alertVC.view setTintColor:[UIColor copperColor]];

UIAlertAction* notifyViaPush = [UIAlertAction
                        actionWithTitle:@"Send Alert to my phone"
                       style:UIAlertActionStyleDefault
                       handler:^(UIAlertAction * action)
                        {
                            [alertVC dismissViewControllerAnimated:YES completion:nil];
                        }];
UIAlertAction* notifyViaEmail = [UIAlertAction
                         actionWithTitle:@"Notify me by email"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                        {
                            [alertVC dismissViewControllerAnimated:YES completion:nil];
                        }];
UIAlertAction* cancel = [UIAlertAction
                                 actionWithTitle:@"Cancel"
                                 style:UIAlertActionStyleCancel
                                 handler:^(UIAlertAction * action)
                                 {
                                     [alertVC dismissViewControllerAnimated:YES completion:nil];
                                 }];

[alertVC addAction:notifyViaPush];
[alertVC addAction:notifyViaEmail];
[alertVC addAction:cancel];

[self presentViewController:alertVC animated:YES completion:nil];

How can I group my buttons and have some space between the actions and cancel button using UIAlertController?

like image 422
nixterrimus Avatar asked Feb 12 '15 21:02

nixterrimus


1 Answers

The line alertVC.view.tintColor = [UIColor copperColor]; is causing problem, it makes the whole view of alert controller the same color, in your first picture the cancel button has white background. To fix this, move this line to the end of the function, that is, after you have added all actions.

like image 187
gabbler Avatar answered Sep 18 '22 12:09

gabbler