Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change one UIAlertAction text color in a UIAlertController

How do I change text color for one UIAlertAction in a UIAlertController and not all of the action buttons.

Here is my code for UIAlertController: I want to change Delete UIAlertAction text color to red.

//Alert to select more method
func moreAlert()
{           
    let optionMenu = UIAlertController(title: "Mere", message: "", preferredStyle: UIAlertControllerStyle.ActionSheet)

    let Edit = UIAlertAction(title: "Rediger", style: .Default, handler: { action in

    })


    let Delete = UIAlertAction(title: "Slet", style: .Default, handler: { action in

    })

    let cancelAction = UIAlertAction(title: "Annullere", style: .Cancel, handler: { action in        
        print("Cancelled")
    })

    optionMenu.addAction(Edit)            
    optionMenu.addAction(Delete)            
    optionMenu.addAction(cancelAction)


    self.presentViewController(optionMenu, animated: true, completion: nil)
}
like image 301
Loc Dai Le Avatar asked Jan 07 '23 12:01

Loc Dai Le


1 Answers

Use the parameter style: .destructive in the initializer for your Delete UIAlertAction

like image 163
Sarah Powell Avatar answered Jan 25 '23 03:01

Sarah Powell