Skip to main content

How to place content outside the safe area

About 2 minSwiftSwiftUIArticle(s)bloghackingwithswift.comcrashcourseswiftswiftuixcodeappstore

How to place content outside the safe area 관련

SwiftUI by Example

Back to Home

How to place content outside the safe area | SwiftUI by Example

How to place content outside the safe area

Updated for Xcode 15

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 ignoresSafeArea() modifier.

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()

Download this as an Xcode projectopen in new window

A phone showing the words “Hello World” over a red background which fills the screen.
A phone showing the words “Hello World” over a red background which fills the screen.

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.

Similar solutions…
How to inset the safe area with custom content | SwiftUI by Example

How to inset the safe area with custom content
How to inset the safe area with custom content | SwiftUI by Example

How to inset the safe area with custom content
How to add extra padding to the safe area | SwiftUI by Example

How to add extra padding to the safe area
How to control the tappable area of a view using contentShape() | SwiftUI by Example

How to control the tappable area of a view using contentShape()
How to indent the content or scroll indicators in a ScrollView | SwiftUI by Example

How to indent the content or scroll indicators in a ScrollView

이찬희 (MarkiiimarK)
Never Stop Learning.