NEW: Get your ticket for Hacking with Swift Live 2019! >>

< How to create different layouts using size classes   Working with state >

How to place content outside the safe area

By default your SwiftUI views will mostly stay inside the safe area – it 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 edgesIgnoringSafeArea() 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: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
    .background(Color.red)
    .edgesIgnoringSafeArea(.all)

HACKING WITH SWIFT LIVE This July is a new two-day event where you'll be inspired by great speakers on day one then learn all the amazing new features from WWDC on day two – click here for more information and tickets.

< How to create different layouts using size classes   Working with state >
MASTER SWIFT NOW
Buy Testing Swift Buy Practical iOS 12 Buy Pro Swift Buy Swift Design Patterns Buy Swift Coding Challenges Buy Server-Side Swift (Vapor Edition) Buy Server-Side Swift (Kitura Edition) Buy Hacking with macOS Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with Swift Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let me know!

Average rating: 5.0/5

Click here to visit the Hacking with Swift store >>