首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIalertcontroller按钮序列

UIalertcontroller按钮序列
EN

Stack Overflow用户
提问于 2016-06-22 18:00:23
回答 2查看 7.9K关注 0票数 2

我想更改警报动作的顺序按钮,根据我尝试的所有可能的代码,但它不允许我改变顺序。

根据HIG,取消在右侧的ref/doc/uid/TP40006556-CH14-SW1

请看我的代码

代码语言:javascript
复制
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"alert" message:@"My alert message" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* noButton = [UIAlertAction
                               actionWithTitle:@"Cancel"
                               style:UIAlertActionStyleCancel
                               handler:^(UIAlertAction * action)
                               {
                                   [alertController dismissViewControllerAnimated:YES completion:nil];
                               }];

UIAlertAction* yesButton = [UIAlertAction
                                actionWithTitle:@"OK"
                                style:UIAlertActionStyleDefault
                                handler:^(UIAlertAction * action)
                                {

                                    [alertController dismissViewControllerAnimated:YES completion:nil];

                                }];


[alertController addAction:yesButton];
[alertController addAction:noButton];
[self presentViewController:alertController animated:YES completion:nil];

这将给我以下结果。我想更改右边的button和左侧的OK button

我很感激你能抽出时间。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-06-22 18:03:22

将取消按钮类型的操作样式更改为UIAlertActionStyleDefault而不是UIAlertActionStyleCancel

代码语言:javascript
复制
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"alert" message:@"My alert message" preferredStyle:UIAlertControllerStyleAlert];


UIAlertAction* yesButton = [UIAlertAction
                            actionWithTitle:@"OK"
                            style:UIAlertActionStyleDefault
                            handler:^(UIAlertAction * action)
                            {

                                [alertController dismissViewControllerAnimated:YES completion:nil];

                            }];

UIAlertAction* noButton = [UIAlertAction
                           actionWithTitle:@"Cancel"
                           style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction * action)
                           {
                               [alertController dismissViewControllerAnimated:YES completion:nil];
                           }];

[alertController addAction:yesButton];
[alertController addAction:noButton];


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

现在只需改变按钮的位置即可更改按钮的顺序。

代码语言:javascript
复制
 [alertController addAction:yesButton]; //If you yesButton to appear first (left)
 [alertController addAction:noButton];

UIAlertActions具有足够的灵活性来重新排序。它们不是固定的。

票数 13
EN

Stack Overflow用户

发布于 2017-05-17 00:54:48

各位,这是一个小旧线程,但是如果您想在正确的按钮中使用粗体字体,只需将该操作设置为警报对象的'.preferredAction‘属性即可。希望这能帮上忙。我刚刚在iOS10上证明了它,它运行得很好。

票数 18
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37975216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档