Instance Method

sizeToFit

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

Declaration

- (void)sizeToFit;

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

A flag used to determine how a view lays out its content when its bounds change.

UIViewContentMode

Options to specify how a view adjusts its content when its size changes.

contentStretch

The rectangle that defines the stretchable and nonstretchable regions of a view.

Deprecated
- sizeThatFits:

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

autoresizesSubviews

A Boolean value that determines whether the receiver automatically resizes its subviews when its bounds change.

autoresizingMask

An integer bit mask that determines how the receiver resizes itself when its superview’s bounds change.