-
-
Save xta/74955b5ca28f1825b00b30e2a1c995e1 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 | |
let width : CGFloat = 82.0 | |
let height : CGFloat = 82.0 | |
struct ContentView: View { | |
@State private var toggle = false | |
var body: some View { | |
VStack { | |
Spacer() | |
ZStack { | |
Image(systemName: "heart.fill") | |
.font(.system(size: 200)) | |
.foregroundColor(toggle ? .red : Color(UIColor.systemGray6)) | |
Button(action: { | |
withAnimation(.easeOut(duration: 0.5)) { | |
toggle.toggle() | |
} | |
}) { | |
HeartStroke() | |
.trim(from: toggle ? 0.99 : 0, to: toggle ? 1 : 0.01) | |
.stroke(style: StrokeStyle(lineWidth: 86, lineCap: .round, lineJoin: .round)) | |
.fill(.white) | |
.shadow(color: .black.opacity(0.2), radius: 10, x: 0, y: 5) | |
.frame(width: width, height: height) | |
} | |
} | |
Spacer() | |
Image("logo") | |
.resizable() | |
.scaledToFit() | |
.frame(width: 120) | |
} | |
} | |
} | |
struct HeartStroke: Shape { | |
func path(in rect: CGRect) -> Path { | |
let path = | |
Path { path in | |
path.move(to: CGPoint(x: -4, y: 5)) | |
path.addLine(to: CGPoint(x: width / 2 , y: height - 20)) | |
path.addLine(to: CGPoint(x: height + 4, y: 5)) | |
} | |
return path | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment