---
title: "sizeThatFits(_:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uiview/sizethatfits(_:)"
---

# sizeThatFits(_:)

Asks the view to calculate and return the size that best fits the specified size.

## Declaration

```swift
func sizeThatFits(_ size: CGSize) -> CGSize
```

## Parameters

- `size`: The size for which the view should calculate its best-fitting size.

## Return Value

Return Value A new size that fits the receiver’s subviews.

## Discussion

Discussion The default implementation of this method returns the existing size of the view. Subclasses can override this method to return a custom value based on the desired layout of any subviews. For example, a UISwitch object returns a fixed size value that represents the standard size of a switch view, and a UIImageView object returns the size of the image it is currently displaying. This method does not resize the receiver.

## See Also

### Related Documentation

- [frame](uikit/uiview/frame.md)
- [bounds](uikit/uiview/bounds.md)

### Configuring the resizing behavior

- [contentMode](uikit/uiview/contentmode-swift.property.md)
- [UIView.ContentMode](uikit/uiview/contentmode-swift.enum.md)
- [sizeToFit()](uikit/uiview/sizetofit().md)
- [autoresizesSubviews](uikit/uiview/autoresizessubviews.md)
- [autoresizingMask](uikit/uiview/autoresizingmask-swift.property.md)
