Смещение между элементами SWIFTUI - PullRequest
0 голосов
/ 11 марта 2020

Я хочу «соединить» мои элементы один за другим, потому что между ними есть пробел. Я пытался использовать свойство ".offset" и не работал на целых устройствах. Проверьте это!

enter image description here

это основной код:

var body: some View {
   ZStack{
       colors["LightGray"]?.edgesIgnoringSafeArea(.all)
           VStack{
               HStack{
                   Text("Notificaciones")
                       .font(.system(size: UIScreen.main.bounds.width * 0.05))
                       .foregroundColor(colors["Black"])
                       .bold()
                       .padding(.trailing, UIScreen.main.bounds.width * 0.5) 
               }.frame(width: UIScreen.main.bounds.width - 40, height: UIScreen.main.bounds.height * 0.08)
                   .background(colors["White"])
                   .clipped()
                   .shadow(radius: 1, x: 0, y: 0)

               HStack{
                   Text("Recordatorio de visita")
                       .foregroundColor(colors["Black"])
                       .font(.system(size: UIScreen.main.bounds.width * 0.035))
                       .bold()
                   Spacer()
                   TextField("#", text: $minutes)
                       .foregroundColor(colors["Gray"])
                       .frame(width:UIScreen.main.bounds.width * 0.10, height:UIScreen.main.bounds.width * 0.10)
                       .padding(.trailing, UIScreen.main.bounds.width * 0.10)
                       .multilineTextAlignment(.trailing)
                   Text("Minutos")
                       .foregroundColor(colors["Black"])
                       .font(.system(size: UIScreen.main.bounds.width * 0.035))
                       .bold()
               }.padding(.all).background(colors["White"]).frame(width:UIScreen.main.bounds.width * 0.892).clipped().shadow(radius: 1, x: 0, y: 0)

               HStack{

                   Toggle(isOn: $checkIn) {

                       Text("Check-In").foregroundColor(colors["Black"]).font(.system(size: UIScreen.main.bounds.width * 0.035)).bold()
                   }.padding()

                   if checkIn {

                   }else{

                   }

               }.background(colors["White"]).frame(width:UIScreen.main.bounds.width * 0.895).clipped().shadow(radius: 1, x: 0, y: 0)

               HStack{

                   Toggle(isOn: $checkOut) {

                       Text("Check-Out").foregroundColor(colors["Black"]).font(.system(size:
UIScreen.main.bounds.width * 0.035)).bold()
                   }.padding()

                   if checkOut {

                   }else{

                   }

               }.background(colors["White"]).frame(width:UIScreen.main.bounds.width *
0.895).clipped().shadow(radius: 1, x: 0, y: 0)

               HStack{

                   Toggle(isOn: $createVisits) {

                       Text("Creación de visita").foregroundColor(colors["Black"]).font(.system(size:
UIScreen.main.bounds.width * 0.035)).bold()
                   }.padding()

                   if createVisits {

                   }else{

                   }

               }.background(colors["White"]).frame(width:UIScreen.main.bounds.width *
0.895).clipped().shadow(radius: 1, x: 0, y: 0)
               HStack{

                   Toggle(isOn: $requestVisits) {

                       Text("Invitación de visita").foregroundColor(colors["Black"]).font(.system(size:
UIScreen.main.bounds.width * 0.035)).bold()
                   }.padding()

                   if requestVisits {

                   }else{

                   }

               }.background(colors["White"]).frame(width:UIScreen.main.bounds.width *
0.895).clipped().shadow(radius: 1, x: 0, y: 0)


               HStack{

                   Toggle(isOn: $reminder) {

                       Text("Recordatorio").foregroundColor(colors["Black"]).font(.system(size:
UIScreen.main.bounds.width * 0.035)).bold()
                   }.padding()

                   if reminder {

                   }else{

                   }

               }.background(colors["White"]).frame(width:UIScreen.main.bounds.width * 0.895).clipped().shadow(radius: 1, x: 0, y: 0)

               HStack{

                   Toggle(isOn: $notificationsEnabled) {

                       Text("No deseo recibir notificaciones").foregroundColor(colors["Black"]).font(.system(size:
UIScreen.main.bounds.width * 0.035)).bold()
                   }.padding()
                       .background(colors["White"])

                   if notificationsEnabled {

                   }else{

                   }

               }.frame(width:UIScreen.main.bounds.width * 0.895).clipped().shadow(radius: 1, x: 0, y: 0)


               HStack{
                   Button(action:{
                   }){
                       HStack{
                           Text("Guardar")
                               .foregroundColor(.white)
                               .background(colors["Purple"])
                               .font(.callout)
                               .frame(width: UIScreen.main.bounds.width * 0.3, height: UIScreen.main.bounds.height * 0.025, alignment: .center)
                       }
                       .padding(.all)
                       .background(colors["Purple"])
                       .cornerRadius(10)
                       .frame(width: UIScreen.main.bounds.width * 0.3, height: UIScreen.main.bounds.height * 0.025, alignment: .center)
                   }
               }.padding()

               Spacer()


       }
   }

}

1 Ответ

1 голос
/ 11 марта 2020

Полагаю, вы имеете в виду, что вам не нужно вертикальное пространство между коробками. Замените ваш VStack на VStack(spacing: 0), сделав так:

var body: some View {
   ZStack{
       colors["LightGray"]?.edgesIgnoringSafeArea(.all)
           VStack(spacing: 0){
               HStack{
                   Text("Notificaciones")
                       .font(.system(size: UIScreen.main.bounds.width * 0.05))
                       .foregroundColor(colors["Black"])
                       .bold()
                       .padding(.trailing, UIScreen.main.bounds.width * 0.5) 
               }.frame(width: UIScreen.main.bounds.width - 40, height: UIScreen.main.bounds.height * 0.08)
                   .background(colors["White"])
                   .clipped()
                   .shadow(radius: 1, x: 0, y: 0)

               HStack{
                   Text("Recordatorio de visita")
                       .foregroundColor(colors["Black"])
                       .font(.system(size: UIScreen.main.bounds.width * 0.035))
                       .bold()
                   Spacer()
                   TextField("#", text: $minutes)
                       .foregroundColor(colors["Gray"])
                       .frame(width:UIScreen.main.bounds.width * 0.10, height:UIScreen.main.bounds.width * 0.10)
                       .padding(.trailing, UIScreen.main.bounds.width * 0.10)
                       .multilineTextAlignment(.trailing)
                   Text("Minutos")
                       .foregroundColor(colors["Black"])
                       .font(.system(size: UIScreen.main.bounds.width * 0.035))
                       .bold()
               }.padding(.all).background(colors["White"]).frame(width:UIScreen.main.bounds.width * 0.892).clipped().shadow(radius: 1, x: 0, y: 0)

               HStack{

                   Toggle(isOn: $checkIn) {

                       Text("Check-In").foregroundColor(colors["Black"]).font(.system(size: UIScreen.main.bounds.width * 0.035)).bold()
                   }.padding()

                   if checkIn {

                   }else{

                   }

               }.background(colors["White"]).frame(width:UIScreen.main.bounds.width * 0.895).clipped().shadow(radius: 1, x: 0, y: 0)

               HStack{

                   Toggle(isOn: $checkOut) {

                       Text("Check-Out").foregroundColor(colors["Black"]).font(.system(size:
UIScreen.main.bounds.width * 0.035)).bold()
                   }.padding()

                   if checkOut {

                   }else{

                   }

               }.background(colors["White"]).frame(width:UIScreen.main.bounds.width *
0.895).clipped().shadow(radius: 1, x: 0, y: 0)

               HStack{

                   Toggle(isOn: $createVisits) {

                       Text("Creación de visita").foregroundColor(colors["Black"]).font(.system(size:
UIScreen.main.bounds.width * 0.035)).bold()
                   }.padding()

                   if createVisits {

                   }else{

                   }

               }.background(colors["White"]).frame(width:UIScreen.main.bounds.width *
0.895).clipped().shadow(radius: 1, x: 0, y: 0)
               HStack{

                   Toggle(isOn: $requestVisits) {

                       Text("Invitación de visita").foregroundColor(colors["Black"]).font(.system(size:
UIScreen.main.bounds.width * 0.035)).bold()
                   }.padding()

                   if requestVisits {

                   }else{

                   }

               }.background(colors["White"]).frame(width:UIScreen.main.bounds.width *
0.895).clipped().shadow(radius: 1, x: 0, y: 0)


               HStack{

                   Toggle(isOn: $reminder) {

                       Text("Recordatorio").foregroundColor(colors["Black"]).font(.system(size:
UIScreen.main.bounds.width * 0.035)).bold()
                   }.padding()

                   if reminder {

                   }else{

                   }

               }.background(colors["White"]).frame(width:UIScreen.main.bounds.width * 0.895).clipped().shadow(radius: 1, x: 0, y: 0)

               HStack{

                   Toggle(isOn: $notificationsEnabled) {

                       Text("No deseo recibir notificaciones").foregroundColor(colors["Black"]).font(.system(size:
UIScreen.main.bounds.width * 0.035)).bold()
                   }.padding()
                       .background(colors["White"])

                   if notificationsEnabled {

                   }else{

                   }

               }.frame(width:UIScreen.main.bounds.width * 0.895).clipped().shadow(radius: 1, x: 0, y: 0)


               HStack{
                   Button(action:{
                   }){
                       HStack{
                           Text("Guardar")
                               .foregroundColor(.white)
                               .background(colors["Purple"])
                               .font(.callout)
                               .frame(width: UIScreen.main.bounds.width * 0.3, height: UIScreen.main.bounds.height * 0.025, alignment: .center)
                       }
                       .padding(.all)
                       .background(colors["Purple"])
                       .cornerRadius(10)
                       .frame(width: UIScreen.main.bounds.width * 0.3, height: UIScreen.main.bounds.height * 0.025, alignment: .center)
                   }
               }.padding()

               Spacer()


       }
   }

}
...