3

Is it possible to give separate tint colors for cancel and other action buttons?. Currently I am changing the tint color as controller.view.tintColor = [UIColor blackColor];

but it changes the tint color for cancel button too. I need to set different tint color say red to the cancel button. Please help me guys.

Sanif SS
  • 602
  • 5
  • 18
  • use destructive style for cancel button to get red color text! – Teja Nandamuri Apr 29 '16 at 15:15
  • @Teja Nandamuri, Sorry didn't get you. Could you please explain? – Sanif SS Apr 29 '16 at 15:21
  • 3
    I meant to say that use the UIAlertAction style as UIAlertActionStyleDestructive for the cancel button. – Teja Nandamuri Apr 29 '16 at 15:22
  • this also could be helpful http://stackoverflow.com/questions/26460706/uialertcontroller-custom-font-size-color – Teja Nandamuri Apr 29 '16 at 15:23
  • @Teja Nandamuri, thanks for the help, the color of UIAlertActionStyleDestructive is default red that is fine. But is there any way to position that button? I want the cancel button at the bottom. Cancel button above all buttons looks weird. – Sanif SS Apr 29 '16 at 15:55
  • it's the way you add action to your alert controller. If you want cancel button to be at top, add it first! If you want it last, add it last! – Teja Nandamuri Apr 29 '16 at 15:56
  • Ohh!, how dumb I am, adding cancel button first and expecting it to be last :P. Thanks a lot Taja bhai. Everything is working as expected :) – Sanif SS Apr 29 '16 at 15:59

1 Answers1

9

set the colour on the alert action as follows:

UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel"....

[cancel setValue:[UIColor redColor] forKey:@"titleTextColor"];

swift:

let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) 
cancelAction.setValue(UIColor.red, forKey: "titleTextColor")
beee
  • 442
  • 5
  • 9