4

I have this lines of code:

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];

I want to change the cancel button color when is selected. How can I do that? Please help.

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Adela Toderici
  • 1,118
  • 13
  • 30
  • Did u check this link http://stackoverflow.com/questions/24157694/change-button-title-color-in-uialertview – jithin Oct 26 '15 at 12:00
  • @jithin I checked this link but the tintColor is changed to default color when the button is selected. My question is about color of button selected. – Adela Toderici Oct 26 '15 at 12:08

3 Answers3

6

try this

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];

try setting the tint color AFTER you present your alert controller:

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

Swift

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)

try setting the tint color AFTER you present your alert controller:

self.presentViewController(alertController, animated: true, completion: { _ in })
alertController.view.tintColor = UIColor.redColor()
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
0

Simply change the tint color on the view of the 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];
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
-1

Try this

Swift

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

Objective-C

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

for more details Click Here.

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Ferrakkem Bhuiyan
  • 2,741
  • 2
  • 22
  • 38