Is there any way of using a gradient as foregroundColor of Text in SwiftUI?
Thanks for the answers in advance!
You can assign any gradient or other type of view as a self-size mask like:
Text("Gradient is on FIRE !!!")
.selfSizeMask(
LinearGradient(
gradient: Gradient(colors: [.red, .yellow]),
startPoint: .bottom,
endPoint: .top)
)
with this simple tiny extension:
extension View {
func selfSizeMask(_ mask: T) -> some View {
ZStack {
self.opacity(0)
mask.mask(self)
}.fixedSize()
}
}