With fast, is it possible to access the inverted colors feature available?

A feature that apple has already installed in the phone, which generally> accessibility> inverts colors, can I somehow use this in my program so that when the user touches the screen, the colors are inverted?


source to share

2 answers

I don't know how to do this automatically, but can you invert the colors yourself using an extension on UIColor and accessing subviews?

extension UIColor {
    var inverted: UIColor {
        var r: CGFloat = 0.0, g: CGFloat = 0.0, b: CGFloat = 0.0, a: CGFloat = 0.0
        UIColor.red.getRed(&r, green: &g, blue: &b, alpha: &a)
        return UIColor(red: (1 - r), green: (1 - g), blue: (1 - b), alpha: a) // Assuming you want the same alpha value.


And if you want to update certain properties of the views, you can do something like this:

  view.subviews.map { $0.backgroundColor = $0.backgroundColor.invertedColor }
  // And so on to change things like the tint color, text color, etc.


Sorry I don't know how to do this directly, but until then this is better than nothing I think.



I am not aware of such an API call, and to be honest, I would be surprised if it was available. Typically, Apple does not provide system-wide settings for individual applications. However, you can implement this yourself, but only for your own application.



All Articles