Wag*_*agh 2 ios uialertcontroller
我想更改警报操作按钮的顺序,根据代码,我尝试了所有可能性,但不允许我更改序列.
在这里查看我的代码
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];
Run Code Online (Sandbox Code Playgroud)
这会给我以下结果.我想在右手边更改取消,button在左手边更改确定button.
我很感激你的时间.
Tej*_*uri 12
将取消按钮类型的操作样式更改为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];
Run Code Online (Sandbox Code Playgroud)
现在,您只需更改位置即可更改按钮的顺序
[alertController addAction:yesButton]; //If you yesButton to appear first (left)
[alertController addAction:noButton];
Run Code Online (Sandbox Code Playgroud)
在UIAlertActions有足够的灵活性来重新排序.它们不是固定的.
Bru*_*lli 12
人们,这是一个有点旧的线程,但如果你想在右键中加上粗体字,你只需要将该操作设置为警告对象的'.preferredAction'属性.希望这可以提供帮助.我刚刚在swift 3/iOS10上证明了它并且它工作得很好.
| 归档时间: |
|
| 查看次数: |
5786 次 |
| 最近记录: |