Search code examples
iosswiftswiftuiuiaccessibilityaccessibility-api

SwiftUI: Detect Display Zoom is on?


This question has been asked before but none of the solutions work. I can't believe that in SwiftUI, similar to @Environment(\.sizeCategory) var sizeCategory there isn't a similar environment variable that we can observe and switch on?


Solution

  • This was working for me (from that other post you referenced):

    private var isZoomed: Bool {
        UIScreen.main.scale < UIScreen.main.nativeScale
    }
    

    I am also using this to determine if bold is toggled on in the accessibility settings.

    @Environment(\.legibilityWeight)
    private var legibilityWeight
    

    with a combination of the text size:

    @Environment(\.sizeCategory)
    private var sizeCategory
    

    I adjust the UI when it becomes too narrow and text too big to fit the text I want.