1

基本上我想要实现的是: 在此处输入图像描述

从上到下淡出图像。我试图用覆盖来做,但它看起来并不好

4

1 回答 1

1

这是一个从顶部到底部淡出图像的工作视图。Lmk 如果它有效!

源代码

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)
    }
}

预览

在此处输入图像描述

于 2021-09-07T18:09:41.823 回答