Skip to content

Instantly share code, notes, and snippets.

@SarahAlsharif
Created October 4, 2022 12:11
Show Gist options
  • Save SarahAlsharif/31b82579eb3ce4fb87752fe3dc3909ab to your computer and use it in GitHub Desktop.
Save SarahAlsharif/31b82579eb3ce4fb87752fe3dc3909ab to your computer and use it in GitHub Desktop.
struct StarsRating: View {
@State var rating : [Rating] = []
func addStars (index : Int) {
var currentRating : Rating = .oneStar
rating.removeAll()
for _ in 0 ... index {
rating.append(currentRating)
currentRating = currentRating.next()
}
}
var body: some View {
ZStack {
Color.blue.opacity(0.2).ignoresSafeArea()
VStack {
MultiStepsView(steps: $rating, extraContent: ["star.fill","star.fill","star.fill","star.fill","star.fill"], extraContentPosition: .onTop, extraContentSize: CGSize(width: 39, height: 30), action: addStars) {
Image(systemName: "star")
.frame(width: 30, height: 30)
}
.accentColor(.yellow)
.font(.title2)
Text(rating.isEmpty ? "How much would you rate this?": "\(rating.last!.rawValue) stars")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment