gpt4 book ai didi

ios - iOS 中的警报 Controller 按钮颜色

转载 作者:行者123 更新时间:2023-11-28 21:10:18 25 4
gpt4 key购买 nike

我有以下实现,它实际上是一个带有两个按钮的警报。它的工作原理和功能。

我遇到的唯一问题是为这两个按钮赋予不同的颜色。现在,它只有一种颜色,即红色。但我希望其中一个是绿色的,另一个是红色的。

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Message" message:nil preferredStyle:UIAlertControllerStyleAlert];

[alert addAction:[UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{

}]];


[alert addAction:[UIAlertAction
actionWithTitle:@"Apply"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
}]];

alert.view.tintColor = [UIColor redColor];

最佳答案

你可以这样做:

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.


UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Message" message:nil preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Default" style:UIAlertActionStyleDefault handler:nil];
[defaultAction setValue:[UIColor redColor] forKey:@"_titleTextColor"];


UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[cancelAction setValue:[UIColor greenColor] forKey:@"_titleTextColor"];

[alertController addAction:defaultAction];
[alertController addAction:cancelAction];

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

Running effect ;否则,如果您使用 UIAlertView 而不是 UIAlertController,则需要自定义警报 View 。

关于ios - iOS 中的警报 Controller 按钮颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43747937/

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