Created
November 11, 2024 17:20
-
-
Save camiloibarrayepes/244cc5895b738a1df6a67ddceb18ef87 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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