try? it out
import SwiftUI
struct RatingView: View {
let stars = 5
let fixedStars = Array(0...4)
var body: some View {
VStack {
Text("SwiftUI can you be my Valentine?")
.padding()
HStack {
ForEach(Array(fixedStars.enumerated()),
id: \.offset) { index, element in
Image(systemName: index < stars ? "heart.fill" : "heart")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 44)
.foregroundColor(.red)
}
}
}
}
}
struct RatingView_Previews: PreviewProvider {
static var previews: some View {
RatingView()
}
}