From fefb4015c78a5ddcf33ed9938cf1052fb511c24c Mon Sep 17 00:00:00 2001 From: Ana Paula Flores Date: Sat, 27 Jan 2024 10:48:25 -0600 Subject: [PATCH] StarRatingfix --- SwiftUIBasics/Views/RatingView.swift | 37 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/SwiftUIBasics/Views/RatingView.swift b/SwiftUIBasics/Views/RatingView.swift index 3ca74af..abcc0e5 100644 --- a/SwiftUIBasics/Views/RatingView.swift +++ b/SwiftUIBasics/Views/RatingView.swift @@ -4,15 +4,34 @@ // // Created by Diplomado on 09/12/23. // - import SwiftUI + struct StarRatingView: View { + @State private var rating: Int = 0 + + var body: some View { + VStack { + Text("Selected Rating: \(rating)") + + HStack { + ForEach(1...5, id: \.self) { index in + Image(systemName: index <= self.rating ? "star.fill" : "star") + .resizable() + .frame(width: 40, height: 40) + .foregroundColor(.yellow) + .onTapGesture { + self.rating = index + } + } + } + } + .padding() + } + } -struct RatingView: View { - var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) - } -} + struct ContentView_Previews: PreviewProvider { + static var previews: some View { + StarRatingView() + } + } + -#Preview { - RatingView() -}