5

Basically what Im trying to achieve is this: enter image description here

To fade an image out from the top to bottom. I tried to do it with overlays but it simply does not look good

1 Answer 1

10

Here is a working view to fade an image out from the top to the bottom. Lmk if it works!

Source Code

struct ContentView: View {
    var body: some View {
        VStack {
            Image("Explore")//Your Image
                .resizable()
        }
        //We can use the LinearGradient in the mask modifier to fade it top to bottom
        .mask(LinearGradient(gradient: Gradient(stops: [
            .init(color: .black, location: 0),
            .init(color: .clear, location: 1),
            .init(color: .black, location: 1),
            .init(color: .clear, location: 1)
        ]), startPoint: .top, endPoint: .bottom))
        .padding()
        .frame(width: 400, height: 400)
    }
}

Preview

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.