@Claude31 thank you so much for letting me know that was my mistake, i appreciate your guidance.
This is the Rating form Im trying to add to the LandmarkDetail that keeps showing up in a small corner with it looks like a spacer before it. im not sure how to fix the issue to so that the form is inline with the landmarks, but i want the review page on each of the landmarks. Thank you!
struct RatingForm: View {
@Binding var rating: Int
@State private var review: String = ""
var label = ""
var maximumRating = 5
var offImage: Image?
var onImage = Image(systemName: "star.fill")
var offColor = Color.gray
var onColor = Color.yellow
var body: some View {
Form {
VStack {
HStack {
Text("How would you rate this Landmark")
}//hstack
HStack{
if label.isEmpty == false {
Text(label)
}//if label
ForEach(1..<maximumRating + 1, id: \.self) { number in
image(for: number)
.foregroundColor(number > rating ? offColor : onColor)
.onTapGesture {
rating = number
}//tapgesture
}//foreach
}//hstack
_HSpacer()
HStack{
Text("Add a review")
}//hstack
HStack{
TextField ("Review the Landmark",
text: $review
)
.frame(
width: 300,
height: 50,
alignment: .center)
}//hstack
}//vstack
Button(action: {
print("Button tapped")
}, label: {
Text("Submit Review")
.frame(
width: 285,
height: 50,
alignment: .center)
.background(Color.pink)
.foregroundColor(.white)
.cornerRadius(8)
}//label
)//button
}//form
}//body
func image(for number: Int) -> Image {
if number > rating {
return offImage ?? onImage
} else {
return onImage
}//else
}//func image
}
struct RatingForm_Previews: PreviewProvider {
static var previews: some View {
RatingForm(rating: .constant(4))
}//static var
}//struct
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: