gpt4 book ai didi

ios - 如何更改 iOS 中的 UIAlertAction 按钮颜色?

转载 作者:可可西里 更新时间:2023-11-01 17:14:56 26 4
gpt4 key购买 nike

我有一个 UIAlertController 和一堆 UIAlertAcion 按钮。现在我需要用其他颜色而不是相同的颜色来显示一个按钮。

对于前者

Button1

Button2

Button3

Button1 and button3 should be in blue

and

button2 should be in red.

这可能吗?怎么办?

只是抛出你的想法...

我的代码:

UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Food Menu" message:@"Select the MenuItem" preferredStyle:UIAlertControllerStyleActionSheet];
for(int i= 0; i<[menus count];i++){

UIAlertAction *action = [UIAlertAction actionWithTitle:[menu objectAtIndex:i] style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
[actionSheet dismissViewControllerAnimated:YES completion:nil];
//do SomeWork

}];

if(i==currentIndex){
//Put button Color Red
}
else{
//put button color Blue
}
[actionSheet addAction:action];
}

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

[actionSheet addAction:cancel];


[self presentViewController:actionSheet animated:YES completion:nil];
}

最佳答案

喜欢更改警报样式:UIAlertActionStyleDestructive

UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:alertTitle
message:alertMessage
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Cancel action");
}];

UIAlertAction *resetAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Reset", @"Reset action")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action)
{
NSLog(@"Reset action");
}];

UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(@"OK action");
}];

[alertController addAction:cancelAction];
[alertController addAction:resetAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];

关于ios - 如何更改 iOS 中的 UIAlertAction 按钮颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33673076/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com