Skip to content

Instantly share code, notes, and snippets.

@AdamWhitcroft
Created June 27, 2024 00:01
Show Gist options
  • Save AdamWhitcroft/0fa47d0ea651cbd31e4d306c5d2e5711 to your computer and use it in GitHub Desktop.
Save AdamWhitcroft/0fa47d0ea651cbd31e4d306c5d2e5711 to your computer and use it in GitHub Desktop.
Custom sheet background color
struct Home: View {
@State private var isShowingSheet: Bool = false
// MARK: - Body
var body: some View {
Text("Custom sheet background")
.onTapGesture {
isShowingSheet.toggle()
}
.sheet(isPresented: $isShowingSheet) {
Text("Sheet")
.onAppear {
setWindowBackgroundColor(.red)
}
}
}
// MARK: - Functions
private func setWindowBackgroundColor(_ color: UIColor) {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let window = windowScene.windows.first {
window.backgroundColor = color
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment