33

iOS 11 has a new feature called "Smart Invert Colors", and I want to take advantage of that in my app. I already have my own dark mode implemented in my app, so I'll do the "color inversion" process myself when Smart Invert is enabled. What I want to know is:

  • How do I tell iOS 11 that the app has a dark interface and don't invert colours, similar to the iOS Clock app in iOS 10+?
  • How do I detect which kind of Invert Colors, specifically "Smart Invert" or "Classic Invert", is enabled?

I've searched everywhere at Google, StackOverflow, and Apple Developer Website for some time now and still couldn't find the answer.

Thanks in advance!

Update:

Thanks to @Toma's answer, I successfully managed to prevent iOS 11 from inverting views in my app. Now I have another problem...

For the detection part, it appears that UIAccessibility.isInvertColorsEnabled (Swift 4.2) will only return true if Smart Invert is on (iOS 11). At least it's enough for me, for now. I’m now wondering how to find out when Classic Invert is on. Post an updated answer below if you know how to do so! Thanks!

General Grievance
  • 4,555
  • 31
  • 31
  • 45
XW_
  • 472
  • 1
  • 5
  • 11
  • 1
    As (an inconvenient) workaround you could create a third "theme" internally for use when smart invert is activated, that would basically be made up of your current dark mode, but inverted. That'll have smart invert, revert your colors to the desired dark mode style. – LinusGeffarth Jun 12 '17 at 13:06

3 Answers3

38

See iOS 11 UIView's property accessibilityIgnoresInvertColors.

toma
  • 1,471
  • 12
  • 20
  • 1
    How can I check if Smart Invert is enabled then? Not Classic Invert, just Smart Invert – XW_ Jun 14 '17 at 15:58
  • I dont know, but I think you will receive `accessibilityIgnoresInvertColors` message to your views)) – toma Jun 14 '17 at 16:00
  • Okay, I'll try that out when I have time, and will mark your answer as accepted if that works :) – XW_ Jun 14 '17 at 16:01
  • Well, it seems like it is currently impossible to do that. If this can be done in the future, feel free to add/edit the answer. – XW_ Jun 14 '17 at 16:53
8

Ignore smart invert for all UIImageViews. Set in app delegate

if #available(iOS 11.0, *) {
   UIImageView.appearance().accessibilityIgnoresInvertColors = true
}
5

Swift 4.2

To check if it smart invert is currently enabled you can use UIAccessibility.isInvertColorsEnabled. You can also get a notification when it changes by observing UIAccessibility.invertColorsStatusDidChangeNotification:

NotificationCenter.default.addObserver(forName: UIAccessibility.invertColorsStatusDidChangeNotification,
                                       object: nil,
                                       queue: OperationQueue.main) {
                                        [weak self] _ in
  
  if UIAccessibility.isInvertColorsEnabled {
    // smart invert is enabled
  } else {
   
  }
}
Community
  • 1
  • 1
Orkhan Alikhanov
  • 9,122
  • 3
  • 39
  • 60