Interactive previews iPhone

ViewThatFits

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

ViewThatFits - 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: 300)
    testContent
      .background(.red.secondary)
      .frame(maxWidth: 200)
    testContent
      .background(.red.tertiary)
      .frame(maxWidth: 100)
    testContent
      .background(.red.quaternary)
      .frame(maxWidth: 50)
  }
}

@ViewBuilder
var testContent: some View {
  ViewThatFits {
    Text("Available width 300")
      .frame(width: 300, height: 20)
      .foregroundStyle(.white)
    Text("Available width 200")
      .frame(width: 200, height: 20)
      .foregroundStyle(.white)
    Text("A. w. 100")
      .frame(width: 100, height: 20)
      .foregroundStyle(.white)
    Text("Fallback")
      .frame(width: 80, height: 20)
      .foregroundStyle(.white)
  }
}

Found an issue or have a suggestion?

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

Connect Wizard

Unlock insights App Store Connect doesn’t show you.

Get Started

More ViewThatFits Components

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

ViewThatFits Vertical

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

Explore Other Components

Browse all
Sheet Corner Radius - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
modifier

Sheet Corner Radius

Requests that the presentation have a specific corner radius.

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

WheelDatePickerStyle

A date picker style that displays each component as columns in a scrollable wheel

Content Unavailable - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
initializer

Content Unavailable

A placeholder for empty results with optional button

ToolbarItem Shared Background Visibility - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
modifier

ToolbarItem Shared Background Visibility

Controls the visibility of the glass background effect on items in the toolbar. In certain contexts, such as the navigation bar on iOS and the window toolbar on macOS, toolbar items will be given a glass background effect that is shared with other items in the same logical grouping

Hour Minute Seconds DatePicker - watchOS - Flat Design - Light Mode - Preview
initializer

Hour Minute Seconds DatePicker

A DatePicker for just hour, minute, and second.

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

SwitchToggleStyle

A toggle style that displays a leading label and a trailing switch.

Toolbar Overflow Menu - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
initializer

Toolbar Overflow Menu

The overflow menu of a toolbar. An overflow menu represents actions that are always placed in the toolbar’s overflow menu, regardless of the toolbar mode, platform, or customizability.

 LinearGaugeStyle - iOS on iPhone - Portrait - Flat Design - Light Mode - Preview
style

LinearGaugeStyle

A gauge style that displays a bar with a marker that appears at a point along the bar to indicate the gauge’s current value