Created
August 24, 2024 23:08
-
-
Save amosgyamfi/bc864ff92b56033e7740134a87891f46 to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// MovingDashPhaseButton.swift | |
// CoreSwiftUI | |
// | |
// Created by Amos Gyamfi on 24.8.2024. | |
// | |
import SwiftUI | |
struct MovingDashPhaseButton: View { | |
@State private var isMovingAround = false | |
var body: some View { | |
ZStack { | |
RoundedRectangle(cornerRadius: 27) | |
.frame(width: 160, height: 54) | |
.foregroundStyle(.indigo.gradient) | |
RoundedRectangle(cornerRadius: 27) | |
.strokeBorder(style: StrokeStyle(lineWidth: 4, lineCap: .round, lineJoin: .round, dash: [40, 400], dashPhase: isMovingAround ? 220 : -220)) | |
.frame(width: 160, height: 54) | |
.foregroundStyle( | |
//RadialGradient(gradient: Gradient(colors: [.white, .indigo, .indigo]), center: .bottom, startRadius: 60, endRadius: 100) | |
LinearGradient(gradient: Gradient(colors: [.indigo, .white, .purple, .mint, .white, .orange, .indigo]), startPoint: .trailing, endPoint: .leading) | |
) | |
.shadow(radius: 2) | |
Button { | |
// | |
} label: { | |
HStack { | |
Text("Get Started") | |
Image(systemName: "arrow.right") | |
} | |
.bold() | |
} | |
.buttonStyle(.plain) | |
} | |
.onAppear { | |
withAnimation(.linear.speed(0.1).repeatForever(autoreverses: false)) { | |
isMovingAround.toggle() | |
} | |
} | |
} | |
} | |
#Preview { | |
MovingDashPhaseButton() | |
.preferredColorScheme(.dark) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment