Change the color of cancel button in UIAlertController with preferredStyle: .ActionSheet

bikram sapkota picture bikram sapkota · Sep 1, 2016 · Viewed 10.2k times · Source

Is it possible to change the color of cancel button to red , i know we can by using Destructive style

  let cancelActionButton: UIAlertAction = UIAlertAction(title: "Cancel", style: .Destructive) { action -> Void in
            print("Cancel")
        }

but i want the cancel button separately , like this enter image description here

Answer

Igor picture Igor · Jul 18, 2017
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) 
cancelAction.setValue(UIColor.red, forKey: "titleTextColor")