Skip to content

Instantly share code, notes, and snippets.

@mageshsridhar
Created February 14, 2022 20:53
Show Gist options
  • Save mageshsridhar/82cbcd7f96446bd56053402445cf0f4b to your computer and use it in GitHub Desktop.
Save mageshsridhar/82cbcd7f96446bd56053402445cf0f4b to your computer and use it in GitHub Desktop.
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()
}
}