Half/full sheet cover SwiftUI

Snehagrawal
2 min readNov 25, 2022

--

SwiftUI uses a declarative syntax, so as to state what the user interface should do. SwiftUI is designed to work alongside UIKit, so we can adopt it incrementally in our existing apps.

  1. Half Sheet Cover: In order to do a half sheet cover, we can do the following steps to implement it;

Step 1: In the .swift file, import SwiftUI.

Step 2: Create a UIHostingController object when you want to integrate SwiftUI views into a UIKit view hierarchy. Use the hosting controller like you would any other view controller, by presenting it or embedding it as a child view controller in your interface.

Step 3: Use a UIViewControllerRepresentable instance to create and manage a UIViewController object in SwiftUI interface. Adopt this protocol in one of your app’s custom instances and use its methods to create, update, and tear down your view controller.

Step 4: Create an extension to create custom views by declaring types that conform to the View protocol.

Step 5: Using it in the SwiftUI view, declare the sheet cover with the above function name, “halfSheet” and declare the ViewController you would want to show up.

2. Full Screen Cover: To create a full screen cover, we can directly use the command “fullScreenCover(isPresented:Binding<Bool>, content: () -> View)” in the SwiftUI view page.

Note: This was my approach to implement the functioality. Any suggestions are welcome..

Like, share and follow to get more interesting content…!!

--

--

Snehagrawal

An assiduous and ingenious Product Manager who has 3+ years of experience building and managing products from scratch to release.