Hi everyone!
I have a custom form that is a list with shadow and in below a button. Because of this design, I had to create a List inside a ScrollView. However, I notice that my list have no height after it. Then, I need to make explicit what the "expected" size of my List.
My question is: how do I use it with the automatic size (calculated using the cells' size)?
The code:
I have a custom form that is a list with shadow and in below a button. Because of this design, I had to create a List inside a ScrollView. However, I notice that my list have no height after it. Then, I need to make explicit what the "expected" size of my List.
My question is: how do I use it with the automatic size (calculated using the cells' size)?
The code:
Code Block struct SwiftUIView: View { var body: some View { ZStack { ScrollView(.vertical, showsIndicators: false) { Spacer() .frame(height: 20) List { ForEach(1...6, id: \.self) { index in VStack(alignment: .trailing, spacing: 5) { Spacer() .frame(height: 5) HStack { Text("title") .foregroundColor(Color.gray) Spacer() } HStack { Text("subtitle") Spacer(minLength: 20) Image(systemName: "pencil") } Spacer() .frame(height: 2) Rectangle() .fill(Color.gray) .frame(width: UIScreen.screenWidth - 50, height: 0.7) } } } .shadow(color: Color.black, radius: 4) .frame(width: UIScreen.screenWidth - 20, height: 500) .padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10)) Spacer() .frame(height: 20) Button(action: { //do the request }, label: { Text("Request") .foregroundColor(Color.white) .frame(width: UIScreen.screenWidth - 60, height: 50) .background(Color.red) .cornerRadius(33) }) } } } } struct SwiftUIView_Previews: PreviewProvider { static var previews: some View { SwiftUIView() } }