Skip to content

Instantly share code, notes, and snippets.

@camiloibarrayepes
Created November 11, 2024 17:20
Show Gist options
  • Select an option

  • Save camiloibarrayepes/244cc5895b738a1df6a67ddceb18ef87 to your computer and use it in GitHub Desktop.

Select an option

Save camiloibarrayepes/244cc5895b738a1df6a67ddceb18ef87 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@State private var moveGradient = true
var body: some View {
slideToPowerOffText(text: "Slide to power off", textColor: .black)
}
func slideToPowerOffText(text: String, textColor: Color) -> some View {
let screenWidth = UIScreen.main.bounds.size.width
return Rectangle()
.overlay {
LinearGradient(
colors: [.clear, .white, .clear],
startPoint: .leading, endPoint: .trailing
)
.frame(width: 150)
.offset(x: moveGradient ? -screenWidth/2 : screenWidth/2)
}
.animation(
.linear(duration: 2)
.repeatForever(
autoreverses: false),
value: moveGradient
)
.mask {
Text(text)
.foregroundColor(textColor)
.font(.largeTitle)
}
.onAppear {
self.moveGradient.toggle()
}
.background(.gray)
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment