Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
¿Por qué LazyHGrid no es tan alto como sus artículos?

Tengo un LazyHGrid que muestra varias vistas de texto en una fila. Ese LazyHGrid está dentro de un VStack. Sin embargo, el LazyHGrid es más alto de lo que debe ser. ¿Qué causa el espacio extra?

 struct ContentView: View { let rows = [GridItem()] var body: some View { VStack { ScrollView(.horizontal) { LazyHGrid(rows: rows) { ForEach(0..<10) { index in Text("Test \(index)") .padding() .foregroundColor(Color.white) .background(Color.black) } } } .background(Color.green) ScrollView(.vertical) { VStack { ForEach(0..<100) { index in Text(String(index)) .frame(maxWidth: .infinity) } } } .background(Color.blue) } } }

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Esto funciona: leyendo la altura de las celdas con una superposición con GeometryReader

 struct ContentView: View { let rows = [ GridItem() ] @State private var contentSize = CGFloat.zero var body: some View { VStack { ScrollView(.horizontal) { LazyHGrid(rows: rows) { ForEach(0..<10) { index in Text("Test \(index)") .padding() .foregroundColor(.white) .background(.black) .overlay( GeometryReader { geo in Color.clear.onAppear { contentSize = geo.size.height } } ) } } } .frame(height: contentSize + 20) .background(Color.green) ScrollView(.vertical) { VStack { ForEach(0..<100) { index in Text(String(index)) .frame(maxWidth: .infinity) } } } .background(Color.blue) } } }
over 4 years ago · Santiago Trujillo Report

0

Solo tiene que agregar el modificador .fixedSize() a su cuadrícula, y funciona...

 LazyHGrid(rows: rows) { ForEach(0..<10) { index in Text("Test \(index)") .padding() .foregroundColor(Color.white) .background(Color.black) } } .fixedSize()

Con tamaño fijo()

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!