---
title: sizeToFit()
framework: uikit
role: symbol
role_heading: Instance Method
path: uikit/uiview/sizetofit()
---

# sizeToFit()

Resizes and moves the receiver view so it just encloses its subviews.

## Declaration

```swift
func sizeToFit()
```

## Mentioned in

Displaying a checkbox in your Mac app built with Mac Catalyst

## Discussion

Discussion Call this method when you want to resize the current view so that it uses the most appropriate amount of space. Specific UIKit views resize themselves according to their own internal needs. In some cases, if a view does not have a superview, it may size itself to the screen bounds. Thus, if you want a given view to size itself to its parent view, you should add it to the parent view before calling this method. You should not override this method. If you want to change the default sizing information for your view, override the sizeThatFits(_:) instead. That method performs any needed calculations and returns them to this method, which then makes the change.

## See Also

### Configuring the resizing behavior

- [contentMode](uikit/uiview/contentmode-swift.property.md)
- [UIView.ContentMode](uikit/uiview/contentmode-swift.enum.md)
- [sizeThatFits(_:)](uikit/uiview/sizethatfits(_:).md)
- [autoresizesSubviews](uikit/uiview/autoresizessubviews.md)
- [autoresizingMask](uikit/uiview/autoresizingmask-swift.property.md)
