iosswiftuicolor

How can I get the default iOS red warning color?


How can I get the default iOS red warning color that is used in UIAlertAction with style UIAlertActionStyle.Destructive without composing the color myself?


Solution

  • There is no API that will allow you to access the color at runtime without creating a UIAlertAction.

    I know it's not exactly what you wanted, but you can do something like this:

    extension UIColor {
        class func destructiveColor() -> UIColor {
            return UIColor(red: 1, green: 0.2196078431, blue: 0.137254902, alpha: 1)
        }
    }
    

    Usage:

    let redColor = UIColor.redColor()
    let destructiveColor = UIColor.destructiveColor()
    

    Note that the two reds are slightly different:

    enter image description here

    Of course, this solution is imperfect because it will not automatically update if Apple tweaks the color.