ios - 在 UIAlertController 中的 Action 下方显示一个空格

标签 ios ios8 uialertcontroller

iOS 8 之前的版本允许我创建一个 UIActionsheet,它会显示一组按钮、一些空格,然后是一个取消按钮。像这样:

Desired Behavior

但是在 iOS 8 中,当我尝试创建相同的外观时,我最终得到的结果如下所示:

iOS 8 Behavior

iOS 8 中的代码如下所示:

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];

如何使用 UIAlertController 对按钮进行分组并在操作和取消按钮之间留出一些空间?

最佳答案

alertVC.view.tintColor = [UIColor copperColor]; 导致问题,它使警报 Controller 的整个 View 颜色相同,在您的第一张图片中,取消按钮具有白色背景。要解决此问题,请将此行移动到函数的末尾,即在您添加所有操作之后。

关于ios - 在 UIAlertController 中的 Action 下方显示一个空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28487743/

相关文章:

ios - 在 Swift 的警报中使用自定义 View

ios - 如何从 iOS 中的音乐播放器(对于 Midi 文件)获取持续时间?

ios - 如何将 View 宽度和高度转换为 CGpoint 坐标?

php异步地穴

swift - 有什么方法可以确定 adjustsFontSizeToFitWidth 是否已触发?

swift - NSUserDefaults Swift/iOS 8 中的 UIColor

ios - 当应用程序进入后台时,如何使我的应用程序弹出到 VC?

iOS viewWillAppear 错误 : "view is not in the window hierarchy"

ios - 如何更改 objective-c 中的字体样式和颜色或操作表?

ios - 在 Swift 2.3 中关闭 UIAlertController 键盘