0Pricing
SwiftUI Academy · Lektion

Views mit frame dimensionieren

Legen Sie Breite, Höhe sowie minimale und maximale Grenzen fest.

Views mit frame dimensionieren ist eine kostenlose SwiftUI Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des SwiftUI Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der SwiftUI Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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.

Häufig gestellte Fragen

Ist die Lektion „Views mit frame dimensionieren“ kostenlos?

Ja — der vollständige Text von „Views mit frame dimensionieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des SwiftUI Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der SwiftUI Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Views mit frame dimensionieren“?

Legen Sie Breite, Höhe sowie minimale und maximale Grenzen fest. Du übst SwiftUI Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um SwiftUI Academy zu starten?

Keine Vorkenntnisse erforderlich. SwiftUI Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.

Wie lange dauert die Lektion „Views mit frame dimensionieren“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser SwiftUI Academy-Lektion Code schreiben und ausführen?

Ja. Jede SwiftUI Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Innenabstand um Views hinzufügen
  2. Views mit frame dimensionieren
  3. Hintergründe und Eckradius
  4. Spacer und Layout-Priorität
← Zurück zu SwiftUI Academy