Created
August 20, 2024 10:15
-
-
Save LukasCZ/33c26988d259c43d39f5e1c15ba589fd to your computer and use it in GitHub Desktop.
iOS 18 tintable widgets helper method
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
// | |
// SwiftUI+tintedWidgets.swift | |
// Timelines | |
// | |
// Created by Lukas Petr on 18.08.2024. | |
// | |
import SwiftUI | |
fileprivate struct LuminanceViewModifier: ViewModifier { | |
@Environment(\.widgetRenderingMode) var renderingMode | |
func body(content: Content) -> some View { | |
if renderingMode == .accented { | |
content | |
.luminanceToAlpha() | |
} else { | |
content | |
} | |
} | |
} | |
extension View { | |
func luminanceToAlphaInAccentedMode() -> some View { | |
modifier(LuminanceViewModifier()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment