UIHostingController + SafeArea

Martin Lasek
Sep 25, 2023

Here’s how you can ignore the safeArea when using a UIHostingController.

The Problem

You are ignoring the safeArea in the most outter view, but when you display it using UIHostingController — it doesn’t work.

The Solution

Add a .frame(maxWidth: .infinity) modifier to your view. Take that view and wrap it inside a ZStack and add the background and ignoreSafeArea modifier to the ZStack.

That’s it. No private _disableSafeArea apis, no hacky extensions. Just pure SwiftUI :)

PS. If this was helpful consider sharing or liking the article ✌🏻

--

--

Martin Lasek

I'm an always optimistic, open minded and knowledge seeking fullstack developer passionate about UI/UX and changing things for the better :)