title: SwiftUI - How to add foreground linear gradient on image
body: <p>I am unable to find any related documentation on how to do a linear gradient on the <strong>foreground</strong> for an image I have with SwiftUI.</p>
  
  <p>I have tried to do it like so:</p>
  
  <pre class="lang-swift prettyprint-override"><code>Image("IconLoseWeight")
    .frame(width: 30.0, height: 30.0)
    .padding(.leading, 17)
    .foregroundColor(LinearGradient(gradient: Gradient(colors: [.white, .black]), startPoint: .top, endPoint: .bottom))
  </code></pre>
  
  <p>Actually, the code shown above doesn't display any errors, but it breaks the code with warnings that make no sense in the top level Stacks (which I think is a bug with Xcode or SwiftUI). If I remove the <code>foreground</code> modifier, the code runs perfectly.</p>