Example:
struct VIPContinueBtnView: View {
@EnvironmentObject var home: HomeGlobal
@State var showShimmer: Bool = false
var body: some View {
ZStack(alignment: .center) {
LinearGradient(gradient: Gradient(colors: [.yellow, .orange]), startPoint: .top, endPoint: .bottom)
.frame(minWidth: 0, maxWidth: .infinity)
.frame(height: home.defaultPadding*3)
.clipShape(Capsule())
Text("立即续费")
.font(home.fontBody)
.bold()
.foregroundColor(.black)
Rectangle()
.frame(minWidth: 0, maxWidth: .infinity)
.frame(height: home.defaultPadding*3)
.foregroundColor(.white)
.opacity(0.8)
.clipShape(Capsule())
.mask (
Capsule()
.fill(LinearGradient(gradient: Gradient(colors: [.clear, .white, .clear]), startPoint: .top, endPoint: .bottom))
.rotationEffect(.degrees(-80))
.offset(x: showShimmer ? 200 : -200)
)
}
.onAppear {
withAnimation(Animation.default.speed(0.2).delay(0).repeatForever(autoreverses: false)) {
self.showShimmer.toggle()
}
}
}
}