0

im trying to create a form that would resemble something like this:

enter image description here

This one is made in bootstrap and thats quite easy, but now i'm learning some Swift UI and the most i got is:

enter image description here

I've tried using VStacks, ZStacks, HStacks, but it doesn't seem to be working as i expected, maybe i'm using them wrong. I need to somehow create a form similar to the one made in boostrap

The SwiftUI Code:

struct FontsGroup: View {

@State var username: String = ""
@State var isPrivate: Bool = true


var body: some View {
    ZStack{
        VStack{
            HStack(
                alignment: .top,
                spacing: 0
            ) {
                
                Form{
                    Section(header:
                                HStack {
                        Text("Nurašoma Prekė")
                        Image(systemName: "staroflife.fill").foregroundColor(.red)
                        
                    }
                    ) {
                        TextField("Username", text: $username)
                        Toggle(isOn: $isPrivate) {
                            Text("Private Account")
                        }
                    }
                    
                }.listRowInsets(EdgeInsets())
                Form{
                    Section(header:
                                HStack {
                        Text("Nurašymo priežastis")
                        Image(systemName: "staroflife.fill").foregroundColor(.red)
                    }
                    ) {
                        TextField("Username", text: $username)
                        Toggle(isOn: $isPrivate) {
                            Text("Private Account")
                        }
                    }
                    
                }.listRowInsets(EdgeInsets())
            }
            HStack(
                alignment: .top,
                spacing: 0
            ) {
                
                Form{
                    Section(header:
                                HStack {
                        Text("Nurašoma Prekė")
                        Image(systemName: "staroflife.fill").foregroundColor(.red)
                        
                    }
                    ) {
                        TextField("Username", text: $username)
                        Toggle(isOn: $isPrivate) {
                            Text("Private Account")
                        }
                    }
                    
                }
                Form{
                    Section(header:
                                HStack {
                        Text("Nurašymo priežastis")
                        Image(systemName: "staroflife.fill").foregroundColor(.red)
                    }
                    ) {
                        TextField("Username", text: $username)
                        Toggle(isOn: $isPrivate) {
                            Text("Private Account")
                        }
                    }
                    
                }
            }
            
            
        }.padding()
    }
    
}  
}

My goal is to have a View with multiple inputs (Best would be 2 columns and as many rows as i need)

Also, i see, that by using these Stacks i make each element scrollable? Is it also to avoid that? Thanks in advance!

ToothFairy
  • 41
  • 9
  • 1
    Try removing all the forms except one. Also, was the SwiftUI code auto generated? Seems kind of weird – aheze Aug 18 '21 at 17:24
  • You are having exactly the same problem as the SwiftUI question before yours. [Spacer not working with Form inside a VStack](https://stackoverflow.com/questions/68836342/spacer-not-working-with-form-inside-a-vstack). The issue is the forms expand to take all available space. – Yrb Aug 18 '21 at 17:25
  • I'm using some kind of UIKit. – ToothFairy Aug 18 '21 at 17:25
  • Also the design that you made in Bootstrap would be pretty hard to do via `Form` (would require using 2 forms, both of which would be scrollable)... probably better to just use normal `Text` + `TextField` – aheze Aug 18 '21 at 17:25
  • @ToothFairy UIKit...? Looks like SwiftUI to me – aheze Aug 18 '21 at 17:26
  • @aheze Sorry, maybe i called it wrong, yeah its just a premade app with swiftui. – ToothFairy Aug 18 '21 at 17:31
  • 1
    @ToothFairy yeah I recommend learning plain, simple SwiftUI instead of using a generator app. You'll get a much better sense of the layout system. [Here](https://www.hackingwithswift.com/100/swiftui)'s a good starting point. – aheze Aug 18 '21 at 17:33

0 Answers0