更改UIAlertController选择的按钮颜色

时间:2015-10-26 11:53:27

标签: ios objective-c swift uialertcontroller

我有这行代码:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
    NSLog(@"cancel registration");
}];
[alertController addAction:cancelAction];
alertController.view.tintColor = [UIColor redColor];

我想在选择时更改取消按钮颜色。我怎样才能做到这一点? 请帮忙。

3 个答案:

答案 0 :(得分:6)

试试这个

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
NSLog(@"cancel registration");
}];
[alertController addAction:cancelAction];
  

尝试设置您呈现警报控制器的色调 AFTER

[self presentViewController: alertController animated:YES completion:nil];
 alertController.view.tintColor = [UIColor redColor];

<强>夫特

var alertController: UIAlertController = UIAlertController.alertControllerWithTitle(title, message: nil, preferredStyle: .ActionSheet)
var cancelAction: UIAlertAction = UIAlertAction.actionWithTitle(cancelTitle, style: .Cancel, handler: {(action: UIAlertAction) -> Void in
    NSLog("cancel registration")
})
alertController.addAction(cancelAction)
  

尝试设置您呈现警报控制器的色调 AFTER

self.presentViewController(alertController, animated: true, completion: { _ in })
alertController.view.tintColor = UIColor.redColor()

答案 1 :(得分:0)

只需更改UIAlertController

视图上的色调颜色
 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
    NSLog(@"cancel registration");
     alertController.view.tintColor = [UIColor redColor];
}];
[alertController addAction:cancelAction];

答案 2 :(得分:-1)

试试这个

<强>夫特

   {
        // Bugfix: iOS9 - Tint not fully Applied without Reapplying
        alertController.view.tintColor = UIColor.redColor()
    }

<强>目标C

   {
        // Bugfix: iOS9 - Tint not fully Applied without Reapplying
        alertController.view.tintColor = [UIColor redColor];
    }

了解更多详情Click Here.