GarySabo
GarySabo

Reputation: 6710

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?

Upvotes: 2

Views: 3259

Answers (1)

Jeff Mark
Jeff Mark

Reputation: 181

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.

Upvotes: 14

Related Questions