Show space below actions in UIAlertController

IOS versions prior to 8 allowed me to create a UIActionsheet that displays a group of buttons, some space and a cancel button. Something like that:

Desired behavior

However, in iOS 8, when I try to create the same look, I get something similar to this:

iOS 8 Behavior

The code in iOS 8 is as follows:

 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 a space between actions and the cancel button using UIAlertController?

+6
source share
2 answers

Line alertVC.view.tintColor = [UIColor copperColor]; causes a problem, it makes the entire look of the warning controller the same color, in the first shot the cancel button has a white background. To fix this, move this line to the end of the function, that is, after you have added all the actions.

+9
source

For me, this worked when I set the UIAlertActionStyleCancel style to UIAlertAction .

In the action code below, there is a UIAlertAction object, and controller is a UIAlertController with a list of actions in style.

 UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { self.tabBarView.selectedIndex = 1; [self.tabBarView setSelectedIndex:self.tabBarView.selectedIndex]; }]; [controller addAction:action]; [controller addAction:action2]; 
+4
source

Source: https://habr.com/ru/post/982402/


All Articles