元素之间的偏移SWIFTUI

问题描述 投票:0回答:1

我想一个个地“加入”我的元素,因为它们之间有一个空格。我尝试使用“ .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()


       }
   }

}
swift swiftui offset
1个回答
0
投票

我假设您的意思是您不希望盒子之间的垂直空间。将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()


       }
   }

}
© www.soinside.com 2019 - 2024. All rights reserved.