Last active
September 30, 2023 02:27
-
-
Save DandyLyons/36cd8c126d6c648c361307bccf5feca4 to your computer and use it in GitHub Desktop.
NightModeView
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
// | |
// NightModeView.swift | |
// | |
// Created by Daniel Lyons on 9/12/23. | |
// | |
import SwiftUI | |
struct NightModeView: View { | |
var body: some View { | |
NavigationStack { | |
List { | |
Image(.blindingWhite) | |
.resizable() | |
.frame(maxWidth: .infinity) | |
.aspectRatio(1.0, contentMode: .fill) | |
Text("This is a text view") | |
Text("Blue").foregroundStyle(.blue) | |
Text("Green").foregroundStyle(.green) | |
Text("Yellow").foregroundStyle(.yellow) | |
NavigationLink("Go to second page", value: "second page") | |
} | |
.navigationTitle("Hello World!") | |
.navigationDestination(for: String.self) { string in | |
Text(string) | |
} | |
} | |
.monochromed(color: .red) | |
} | |
} | |
extension View { | |
func monochromed(color: Color, colorScheme: ColorScheme = .dark) -> some View { | |
let filter: some View = color | |
.blendMode(.color) | |
.opacity(0.5) | |
.allowsHitTesting(false) | |
return self | |
.preferredColorScheme(colorScheme) | |
.tint(color) | |
.overlay { | |
filter | |
.ignoresSafeArea() | |
} | |
.colorMultiply(color) | |
} | |
} | |
#Preview { | |
NightModeView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment