更改UIAlertController选择的按钮颜色

Ade*_*ici 4 objective-c ios 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];
Run Code Online (Sandbox Code Playgroud)

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

Anb*_*hik 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];
Run Code Online (Sandbox Code Playgroud)

尝试在显示警报控制器设置色调颜色:

[self presentViewController: alertController animated:YES completion:nil];
 alertController.view.tintColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)

迅速

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)
Run Code Online (Sandbox Code Playgroud)

尝试在显示警报控制器设置色调颜色:

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