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

# sizeThatFits(_:)

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

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

## Parameters

`size`

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

## Return Value

A new size that fits the receiver’s subviews.

## 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`](/documentation/UIKit/UISwitch) object returns a fixed size value that represents the standard size of a switch view, and a [`UIImageView`](/documentation/UIKit/UIImageView) object returns the size of the image it is currently displaying.

This method does not resize the receiver.

## See Also

[`frame`](/documentation/UIKit/UIView/frame)

The frame rectangle, which describes the view’s location and size in its superview’s coordinate system.

[`bounds`](/documentation/UIKit/UIView/bounds)

The bounds rectangle, which describes the view’s location and size in its own coordinate system.



---

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)