从上到下淡出图像。我试图用覆盖来做,但它看起来并不好
问问题
59 次
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 回答