Updated for Xcode 13.3
By default your SwiftUI views will mostly stay inside the safe area – they will go to the bottom of the screen, but it won’t go near any notch at the top of the device.
If you want to change that – if you want your view to be truly full screen, even if that means being partly obscured by a notch or other hardware cut outs – then you should use the
For example, this creates a red text view that asks to fill all available space, then sets it to ignore any safe areas so that it goes truly edge to edge.
Text("Hello World") .frame(minWidth: 100, maxWidth: .infinity, minHeight: 100, maxHeight: .infinity) .background(.red) .ignoresSafeArea()
There is a second, similar modifier called
safeAreaInset(), which allows us to place distinct content outside the safe area while also adjusting the remaining safe area so that all its contents remain visible.
SPONSORED Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!
Link copied to your pasteboard.