Layout in SwiftUI with horizontal and vertical alignment

后端 未结 6 2065
别跟我提以往
别跟我提以往 2021-02-04 09:11

I\'m trying to accomplish this layout

If I try HStack wrapped in VStack, I get this:

If I try VStack wrapped in HStack, I get this:

6条回答
  •  生来不讨喜
    2021-02-04 09:27

        var body: some View {
    
        VStack {
            HStack {
                Text("Username")
                Spacer()
                TextField($username)
                    .textFieldStyle(.roundedBorder)
                    .frame(maxWidth: 200)
                    .foregroundColor(.gray)
                    .accentColor(.red)
            }
            .padding(.horizontal, 20)
            HStack {
                Text("Email")
                Spacer()
                TextField($email)
                    .textFieldStyle(.roundedBorder)
                    .frame(maxWidth: 200)
                    .foregroundColor(.gray)
                }
                .padding(.horizontal, 20)
            HStack {
                Text("Password")
                Spacer()
                TextField($password)
                    .textFieldStyle(.roundedBorder)
                    .frame(maxWidth: 200)
                    .foregroundColor(.gray)
                }
                .padding(.horizontal, 20)
        }
    }
    

提交回复
热议问题