View ModifieriOS 15.0+macOS 10.15+tvOS 15.0+watchOS 9.0+visionOS 1.0+
Overloads
2 ways to call compose().controlSize(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().controlSize(controlSize: SwiftUI.ControlSize)nonisolated func controlSize(_ controlSize: ControlSize) -> some ViewParameters
controlSize*SwiftUI.ControlSizeOne of the control sizes specified in the
ControlSizeenumeration.
Discussion
Use controlSize(_:) to override the system default size for controls
in this view. In this example, a view displays several typical controls
at .mini, .small and .regular sizes.
struct ControlSize: View {
var body: some View {
VStack {
MyControls(label: "Mini")
.controlSize(.mini)
MyControls(label: "Small")
.controlSize(.small)
MyControls(label: "Regular")
.controlSize(.regular)
}
.padding()
.frame(width: 450)
.border(Color.gray)
}
}
struct MyControls: View {
var label: String
@State private var value = 3.0
@State private var selected = 1
var body: some View {
HStack {
Text(label + ":")
Picker("Selection", selection: $selected) {
Text("option 1").tag(1)
Text("option 2").tag(2)
Text("option 3").tag(3)
}
Slider(value: $value, in: 1...10)
Button("OK") { }
}
}
}See also
More in Layout.
- alignmentGuideSets the view's vertical alignment.
- aspectRatioConstrains this view's dimensions to the specified aspect ratio.
- containerCornerOffsetAdjusts the view's layout to avoid the container view's corner insets for the specified edges.
- containerRelativeFramePositions this view within an invisible frame with a size relative to the nearest container.
- defaultScrollAnchorAssociates an anchor to control which part of the scroll view's content should be rendered by default.
- dynamicTypeSizeSets the Dynamic Type size within the view to the given value.
- fixedSizeFixes this view at its ideal size.
- flipsForRightToLeftLayoutDirectionSets whether this view mirrors its contents horizontally when the layout direction is right-to-left.
- framePositions this view within an invisible frame.
- geometryGroupIsolates the geometry (e.g. position and size) of the view from its parent view.
- gridCellAnchorSpecifies a custom alignment anchor for a view that acts as a grid cell.
- gridCellColumnsTells a view that acts as a cell in a grid to span the specified number of columns.