Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS中的警报控制器按钮颜色_Ios_Objective C_Uialertcontroller - Fatal编程技术网

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。您需要自定义警报视图。