Created
July 3, 2023 19:24
-
-
Save dropski/de24066880c57887d67dbd3f9ee3d875 to your computer and use it in GitHub Desktop.
SwiftUI Simple Rating View
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
struct ContentView: View { | |
@State private var selectedIndex: Int = -1 | |
var body: some View { | |
VStack { | |
HStack { | |
ForEach(0..<5) { index in | |
Image(systemName: "star.fill") | |
.transition(.opacity) | |
.foregroundColor(index <= selectedIndex ? .yellow : .gray) | |
.onTapGesture { | |
withAnimation { | |
selectedIndex = index | |
} | |
} | |
} | |
} | |
} | |
.foregroundColor(.white) | |
.frame(width: 200, height: 300) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment