0

I try to build a view in SwiftUI with 2 views vertically arranged. i can not have the top view smaller than the bottom view.

import SwiftUI

struct SettingList: View {
    @State var texte: String = "tttttttttttttttt"
    var body: some View {
        VStack{
            List {
                Section {
                    HStack {
                        Text("bbb")
                        Spacer()
                        TextField("texte : ", text: $texte)
                    }
                    HStack {
                        Text("bbb")
                        Spacer()
                        TextField("texte : ", text: $texte)
                    }
                    HStack {
                        Text("bbb")
                        Spacer()
                        TextField("texte : ", text: $texte)
                    }
                } header: {
                    Text("Settings")
                        .font(.title)
                }
            }
            List {
                Section {
                    ForEach(0..<26) { i in
                        Text("Placeholder \(i)")
                    }
                } header: {
                    Text("List")
                        .font(.title)
                }
                .font(.title2)
            }
        }
    }
}

struct SettingList_Previews: PreviewProvider {
    static var previews: some View {
        SettingList()
    }
}

What I get is that the 2 List in th VStacvk have same height. I would like to have the top one use only space needed for the (3 in this examples) lines with no scrolling , while bottom can take the other part of the view and be able to scroll.

I tried with fixedSize() but could not get better results.

Have you any idea ? Thanks for your time.

Ptit Xav
  • 3,006
  • 2
  • 6
  • 15
  • `List` (and other types of scroll view) will by default take as much space as they are given. If you are looking for "no scrolling", then you likely want to find a different component (just a `VStack` for instance). – jnpdx Feb 11 '22 at 17:37
  • @jnpdx , I already tried with VStack,Form, but I lost the “list” formatting of lines. – Ptit Xav Feb 11 '22 at 17:53
  • Yes, you'd need to implement that yourself – jnpdx Feb 11 '22 at 17:53

0 Answers0