Skip to content

Instantly share code, notes, and snippets.

@dropski
Created July 3, 2023 19:24
Show Gist options
  • Save dropski/de24066880c57887d67dbd3f9ee3d875 to your computer and use it in GitHub Desktop.
Save dropski/de24066880c57887d67dbd3f9ee3d875 to your computer and use it in GitHub Desktop.
SwiftUI Simple Rating View
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