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

# systemLayoutSizeFitting(_:withHorizontalFittingPriority:verticalFittingPriority:)

Returns the optimal size of the view based on its constraints and the specified fitting priorities.

```
func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> 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).

`horizontalFittingPriority`

The priority for horizontal constraints. Specify [`fittingSizeLevel`](/documentation/UIKit/UILayoutPriority/fittingSizeLevel) to get a width that is as close as possible to the width value of `targetSize`.

`verticalFittingPriority`

The priority for vertical constraints. Specify [`fittingSizeLevel`](/documentation/UIKit/UILayoutPriority/fittingSizeLevel) to get a height that is as close as possible to the height value of `targetSize`.

## Return Value

The optimal size for the view based on the provided constraint priorities.

## Discussion

Use this method when you want to prioritize the view’s constraints when determining the best possible size of the view.  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)