Created
June 27, 2024 00:01
-
-
Save AdamWhitcroft/0fa47d0ea651cbd31e4d306c5d2e5711 to your computer and use it in GitHub Desktop.
Custom sheet background color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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