How to set Root view Controller & Statusbar Height in SwiftUI

Published December 26, 2021

In this SwiftUI example we will learn how to set rootview controller. After Creating Your SwiftUI Project. Follow below steps to create dashboard screen

 

Open your project Go to File —> New —> File… Here You can select a SwiftUI View in User Interface and Click on Next —> Give a name for your file (Here i given Home as File name) and Click on Create

SwiftUI Rootview and statusbar height

 

Go to SceneDelegate change rootView as Home under willConnectTo session Delegate. Because here i want to show Home View as soon as App launch.

 

SwiftUI set statusbar height

 

Below code will set the height of Statusbar in swiftUI

let window = UIApplication.shared.windows.filter {$0.isKeyWindow}.first

let statusBarHeight = window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0

let screen = UIScreen.main.bounds