ViewThatFits
struct · iOS 16.0+ · SDK 27.1
@frozen nonisolated struct ViewThatFits<Content> where Content : ViewA view that adapts to the available space by providing the first child view that fits. `ViewThatFits` evaluates its child views in the order you provide them to the initializer. It selects the first child whose ideal size on the constrained axes fits within the proposed size. This means that you provide views in order of preference. Usually this order is largest to smallest, but since a view might fit along one constrained axis but not the other, this isn't always the case. By default, `ViewThatFits` constrains in both the horizontal and vertical axes. The following example shows an `UploadProgressView` that uses `ViewThatFits` to display the upload progress in one of three ways. In order, it attempts to display: * An ``HStack`` that contains a ``Text`` view and a ``ProgressView``. * Only the `ProgressView`. * Only the `Text` view. The progress views are fixed to a 100-point width. struct UploadProgressView: View { var uploadProgress: Double var body: some View { ViewThatFits(in: .horizontal) { HStack { Text("\(uploadProgress.formatted(.percent))") ProgressView(value: uploadProgress) .frame(width: 100) } ProgressView(value: uploadProgress) .frame(width: 100) Text("\(uploadProgress.formatted(.percent))") } } } This use of `ViewThatFits` evaluates sizes only on the horizontal axis. The following code fits the `UploadProgressView` to several fixed widths: VStack { UploadProgressView(uploadProgress: 0.75) .frame(maxWidth: 200) UploadProgressView(uploadProgress: 0.75) .frame(maxWidth: 100) UploadProgressView(uploadProgress: 0.75) .frame(maxWidth: 50) } 
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
ViewThatFits.init(in:content:)
callback cannot propagate synchronous failure