---
title: "systemLayoutSizeFitting(_:withHorizontalFittingPriority:verticalFittingPriority:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uiview/systemlayoutsizefitting(_:withhorizontalfittingpriority:verticalfittingpriority:)"
---

# systemLayoutSizeFitting(_:withHorizontalFittingPriority:verticalFittingPriority:)

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

## Declaration

```swift
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 doc://com.apple.uikit/documentation/UIKit/UIView/layoutFittingCompressedSize. To obtain a view that is as large as possible, specify the constant doc://com.apple.uikit/documentation/UIKit/UIView/layoutFittingExpandedSize.
- `horizontalFittingPriority`: The priority for horizontal constraints. Specify doc://com.apple.uikit/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 doc://com.apple.uikit/documentation/UIKit/UILayoutPriority/fittingSizeLevel to get a height that is as close as possible to the height value of targetSize.

## Return Value

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

## Discussion

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.

## See Also

### Measuring in Auto Layout

- [systemLayoutSizeFitting(_:)](uikit/uiview/systemlayoutsizefitting(_:).md)
- [intrinsicContentSize](uikit/uiview/intrinsiccontentsize.md)
- [invalidateIntrinsicContentSize()](uikit/uiview/invalidateintrinsiccontentsize().md)
- [contentCompressionResistancePriority(for:)](uikit/uiview/contentcompressionresistancepriority(for:).md)
- [setContentCompressionResistancePriority(_:for:)](uikit/uiview/setcontentcompressionresistancepriority(_:for:).md)
- [contentHuggingPriority(for:)](uikit/uiview/contenthuggingpriority(for:).md)
- [setContentHuggingPriority(_:for:)](uikit/uiview/setcontenthuggingpriority(_:for:).md)
