Skip to content

Instantly share code, notes, and snippets.

@LukasCZ
Created August 20, 2024 10:15
Show Gist options
  • Save LukasCZ/33c26988d259c43d39f5e1c15ba589fd to your computer and use it in GitHub Desktop.
Save LukasCZ/33c26988d259c43d39f5e1c15ba589fd to your computer and use it in GitHub Desktop.
iOS 18 tintable widgets helper method
//
// 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