I have the following list, inside each row of the list there is a view which is a colorful rectangle and a text inside (it's the background of the text in the shape of rectangle).
import SwiftUI
struct ListRow: View {
var name:String
var factor : CGFloat
var fillColor:Color
var body: some View {
GeometryReader { geometry in
VStack(spacing: 0) {
Text(self.name)
.frame(width: geometry.size.width, height: self.factor *
geometry.size.height)
.background(RoundedRectangle(cornerRadius:
5).fill(self.fillColor)).foregroundColor(.white)
Spacer()
}
}
}
}
I am trying to control the positioning of the rectangle within the lists row height. Each rectangle have it's height, the problem is that regardless of it's height the rectangle always appear in the center of the list row . I have tried to use alignment:.top
inside the VStack of listRow or the frame() of text, but there is no effect..
import SwiftUI
struct ListView: View {
var range = 1...12
var body: some View {
List(self.range,id:\.self){
num in
ListRow(name: "Some Name", factor: CGFloat(1.5),fillColor:Color(.pink)).padding()
}
}
}
How can I make the internal view appear from the top of the list row ?