iPhone SwiftUI layouts
Explore SwiftUI APIs, components, and modifiers with interactive iPhone previews, Swift code, and Apple documentation. Compare every available orientation, appearance, and design.
201elements
ViewThatFits
ViewThatFits Vertical
A view that adapts to the available vertical space by providing the first child view that fits.
Explore ViewThatFits Vertical on iPhone in portrait, with SwiftUI code and Apple API documentation.
SwiftUI code
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)
}
}Compatibility
iOS 16.0+ iPadOS 16.0+ macOS 13.0+ watchOS 9.0+ tvOS 16.0+ visionOS 1.0+
Tags
Found an issue or have a suggestion?
All variants
Every available iPhone screenshot for ViewThatFits Vertical.