我有这行代码:
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];
我想在选择时更改取消按钮颜色。我怎样才能做到这一点? 请帮忙。
答案 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.