Change background color of the status bar and bottom I am migrating from Storyboard to Swift UI.
I did the following:
The problem is the background color of the status bar and the very bottom is black instead of white.
I tried to search stack overflow but I can’t find any valid solution
Any idea on how to fix it?
import UIKit
import SwiftUI
struct NotificationScreen: View {
var body: some View {
ZStack {
Color.white
.ignoresSafeArea(edges: .all) // Ensure it covers the entire screen, including the unsafe area
VStack {
Text("Hello!")
.foregroundColor(.white)
}
}
}
}
#Preview {
NotificationScreen()
}
class NotificationVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let swiftUIView = NotificationScreen()
let hostingController = UIHostingController(rootView: swiftUIView)
addChild(hostingController)
view.addSubview(hostingController.view)
hostingController.didMove(toParent: self)
}
}
Solved it by
self.view.backgroundColor = .white