<!--
{
  "availability" : [
    "iOS: 6.0.0 -",
    "iPadOS: 6.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIView/systemLayoutSizeFitting(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIView(im)systemLayoutSizeFittingSize:"
  },
  "title" : "systemLayoutSizeFitting(_:)"
}
-->

# systemLayoutSizeFitting(_:)

Returns the optimal size of the view based on its current constraints.

```
func systemLayoutSizeFitting(_ targetSize: CGSize) -> CGSize
```

## Parameters

`targetSize`

The size that you prefer for the view. To obtain a view that is as small as possible, specify the constant [`layoutFittingCompressedSize`](/documentation/UIKit/UIView/layoutFittingCompressedSize). To obtain a view that is as large as possible, specify the constant [`layoutFittingExpandedSize`](/documentation/UIKit/UIView/layoutFittingExpandedSize).

## Return Value

The optimal size for the view.

## Discussion

This method returns a size value for the view that optimally satisfies the view’s current constraints and is as close to the value in the `targetSize` parameter as possible. This method does not actually change the size of the view.

---

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)