Interactive previews iPhone

ViewThatFits Vertical

A view that adapts to the available vertical space by providing the first child view that fits.

ViewThatFits Vertical - iOS on iPhone - Portrait - Flat Design - Light Mode - Preview

Platform Compatibility

iOS 16.0+ iPadOS 16.0+ macOS 13.0+ watchOS 9.0+ tvOS 16.0+ visionOS 1.0+

Tags

SwiftUI Code

Docs
var body: some View {
  VStack(alignment: .leading) {
    testContent
      .background(.red)
      .frame(maxWidth: 200)
    testContent
      .background(.red.secondary)
      .frame(maxHeight: 20)
    testContent
      .background(.red.tertiary)
      .frame(maxHeight: 9)
  }
}

@ViewBuilder
var testContent: some View {
  ViewThatFits(in: .vertical) {
    Text("Size w300 h30")
      .frame(width: 300, height: 30)
      .foregroundStyle(.white)
    Text("Size w200 h20")
      .frame(width: 200, height: 20)
      .foregroundStyle(.white)
    Text("Fallback")
      .frame(width: 80, height: 10)
      .foregroundStyle(.white)
  }
}

Found an issue or have a suggestion?

Created: May 29, 2025Updated: May 31, 2025

More ViewThatFits Components

View all
ViewThatFits - iOS on iPhone - Portrait - Flat Design - Light Mode - Preview
initializer

ViewThatFits

A view that adapts to the available space by providing the first child view that fits.

Explore Other Components

Browse all
InsetListStyle - iOS on iPhone - Portrait - Flat Design - Light Mode - Preview
style

InsetListStyle

The list style that describes the behavior and appearance of an inset list.

GraphicalDatePickerStyle - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
style

GraphicalDatePickerStyle

A date picker style that displays an interactive calendar or clock

Compact Photos Picker Style - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
style

Compact Photos Picker Style

A photos picker style that displays the picker without presenting a sheet.

List Row Separator Tint - iOS on iPhone - Portrait - Flat Design - Light Mode - Preview
modifier

List Row Separator Tint

Sets the tint color associated with a row.

SegmentedPickerStyle - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
style

SegmentedPickerStyle

A picker style that presents the options in a segmented control. Use this style when there are two to five options. Consider using menu when there are more than five options.

Content Unavailable Search Text - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
type

Content Unavailable Search Text

A pre-built placeholder for empty search results with search text

InlinePickerStyle - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
style

InlinePickerStyle

A PickerStyle where each option is displayed inline with other views in the current container.

UIKit Content Background colors - iOS on iPhone - Portrait - Flat Design - Light Mode - Preview
type

UIKit Content Background colors

The UIKit colors that are also used in other components like in List and GroupBox