0Pricing
SwiftUI Academy · Lección

Dimensionamiento de vistas con frame

Establezca restricciones de ancho, alto y valores mínimos y máximos.

Dimensionamiento de vistas con frame es una lección gratuita de SwiftUI Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de SwiftUI Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de SwiftUI Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

Views Size Themselves

By default a SwiftUI view is exactly as big as its content needs. When you want a specific size, you reach for the frame modifier to ask for one.

A Fixed Width and Height

The frame modifier lets you request an exact size. Here the text is placed inside a box that is 200 points wide and 80 points tall.

Text("Card")
    .frame(width: 200, height: 80)

Width Only

You do not have to set both dimensions. Give only a width and the height stays natural, sized to fit the content as usual.

Text("Wide")
    .frame(width: 250)

Filling Available Space

Set maxWidth to infinity to let a view stretch across all the space its parent offers. This is great for full-width buttons and rows.

Text("Stretch")
    .frame(maxWidth: .infinity)

Aligning Inside the Frame

A roomy frame centers its content by default. The alignment argument moves that content, like pinning text to the leading edge.

Text("Left")
    .frame(maxWidth: .infinity, alignment: .leading)

Minimum Sizes

Use minWidth or minHeight to guarantee a view never shrinks below a floor, even when content is tiny. Handy for consistent tap targets.

Text("OK")
    .frame(minWidth: 120)

Maximum Sizes

The maxWidth and maxHeight values cap how large a flexible view can grow, so it stretches only up to a limit you choose.

Text("Capped")
    .frame(maxWidth: 400)

Combining Min and Max

Mix minWidth and maxWidth for a flexible range. The view grows with its parent but stays between a comfortable lower and upper bound.

Text("Flexible")
    .frame(minWidth: 100, maxWidth: 300)

Frame and Background Together

A frame defines the area a background fills. Set a frame, then add a color, and the whole sized region is painted, not just the text.

Text("Tile")
    .frame(width: 120, height: 120)
    .background(.mint)

Frame Wraps, It Does Not Clip

A frame proposes a size but never trims content by itself. If content is larger than the frame, it can spill out unless you also clip it.

Frame Plus Padding

Combine the two tools for polished layouts: a frame sets the overall size and padding adds the inner breathing room around the content.

Text("Spaced")
    .padding()
    .frame(maxWidth: .infinity)

Quick Check

Check your understanding of the frame modifier.

Recap

Great progress! You can now use frame to set exact sizes, flexible ranges, fill space with infinity, and align content inside the area.

Preguntas frecuentes

¿La lección «Dimensionamiento de vistas con frame» es gratis?

Sí — el texto completo de «Dimensionamiento de vistas con frame» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de SwiftUI Academy, actualiza a CoddyKit PRO. El curso de SwiftUI Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Dimensionamiento de vistas con frame»?

Establezca restricciones de ancho, alto y valores mínimos y máximos. Practicas SwiftUI Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar SwiftUI Academy?

No se requiere experiencia previa. SwiftUI Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.

¿Cuánto tiempo toma la lección «Dimensionamiento de vistas con frame»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de SwiftUI Academy?

Sí. Cada lección de SwiftUI Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Añadir relleno alrededor de las vistas
  2. Dimensionamiento de vistas con frame
  3. Fondos y radio de esquina
  4. Spacer y prioridad de diseño
← Volver a SwiftUI Academy