<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/buttonSizing(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE12buttonSizingyQrAA06ButtonE0VF"
  },
  "title" : "buttonSizing(_:)"
}
-->

# buttonSizing(_:)

The preferred sizing behavior of buttons in the view hierarchy.

```
nonisolated func buttonSizing(_ sizing: ButtonSizing) -> some View
```

## Parameters

`sizing`

A button sizing behavior that may be used to
influence the primary axis size of buttons capable of adapting to it.

## Discussion

Views may use the specified button sizing when determining the size they
choose to be in their primary axis within their parent view’s proposed
size.

Many built-in controls that display as a button adapt to this view
modifier. For example, you can make certain styles of [`Button`](/documentation/SwiftUI/Button),
[`Picker`](/documentation/SwiftUI/Picker), [`ControlGroup`](/documentation/SwiftUI/ControlGroup), and [`Toggle`](/documentation/SwiftUI/Toggle) flexible by applying
this modifier to them or their container.

This example creates a button that spans the width of its container,
which you may want to do if the button is placed in a narrow context,
like the sidebar of a welcome window.

```
Button("Open Document…", action: openDocument)
    .buttonSizing(.flexible)
```

Your own views and styles can adapt to this view modifier by reading the
[`buttonSizing`](/documentation/SwiftUI/EnvironmentValues/buttonSizing) environment value and applying an
appropriate frame.

```
struct CustomButtonStyle: ButtonStyle {
    @Environment(\.buttonSizing) private var buttonSizing

    private var maxWidth: CGFloat {
        switch buttonSizing {
        case .flexible: .infinity
        case .fitted, _: nil
        }
    }

    func makeBody(configuration: Configuration) -> some View {
        configuration.content
            .frame(maxWidth: maxWidth)
            .background(.tint, in: Capsule())
    }
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)