我想更改警报动作的顺序按钮,根据我尝试的所有可能的代码,但它不允许我改变顺序。
根据HIG,取消在右侧的ref/doc/uid/TP40006556-CH14-SW1
请看我的代码
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。

我很感激你能抽出时间。
发布于 2016-06-22 18:03:22
将取消按钮类型的操作样式更改为UIAlertActionStyleDefault而不是UIAlertActionStyleCancel
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];现在只需改变按钮的位置即可更改按钮的顺序。
[alertController addAction:yesButton]; //If you yesButton to appear first (left)
[alertController addAction:noButton];UIAlertActions具有足够的灵活性来重新排序。它们不是固定的。
发布于 2017-05-17 00:54:48
各位,这是一个小旧线程,但是如果您想在正确的按钮中使用粗体字体,只需将该操作设置为警报对象的'.preferredAction‘属性即可。希望这能帮上忙。我刚刚在iOS10上证明了它,它运行得很好。
https://stackoverflow.com/questions/37975216
复制相似问题