Created
February 14, 2022 20:53
-
-
Save mageshsridhar/82cbcd7f96446bd56053402445cf0f4b 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
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
Preview https://www.reddit.com/r/iOSProgramming/comments/ssil8q/made_this_heart_toggle_using_paths_in_swiftui/?utm_source=share&utm_medium=ios_app&utm_name=iossmf