iOS中的警报控制器按钮颜色
我有以下实现,它实际上是一个带有两个按钮的警报。它工作正常,功能正常 唯一的问题是,我必须给这两个按钮不同的颜色。现在,它只有一种颜色,那就是红色。但我希望其中一个是绿色的,另一个是红色的iOS中的警报控制器按钮颜色,ios,objective-c,uialertcontroller,Ios,Objective C,Uialertcontroller,我有以下实现,它实际上是一个带有两个按钮的警报。它工作正常,功能正常 唯一的问题是,我必须给这两个按钮不同的颜色。现在,它只有一种颜色,那就是红色。但我希望其中一个是绿色的,另一个是红色的 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Message" message:nil preferredStyle:UIAlertControllerStyleAlert]; [alert addActio
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];
}
);否则,如果使用UIAlertView而不是UIAlertController,则需要自定义警报视图 您可以这样做:
- (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];
}
);否则,如果使用UIAlertView而不是UIAlertController,则需要自定义警报视图 没有支持您所需内容的公共API。您需要自定义警报视图。没有支持所需内容的公共API。您需要自定义警报视图。