systemLayoutSizeFitting(_:withHorizontalFittingPriority:verticalFittingPriority:)
Returns the optimal size of the view based on its constraints and the specified fitting priorities.
Declaration
func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSizeParameters
- targetSize:
The size that you prefer for the view. To obtain a view that is as small as possible, specify the constant Layoutfittingcompressedsize. To obtain a view that is as large as possible, specify the constant Layoutfittingexpandedsize.
- horizontalFittingPriority:
The priority for horizontal constraints. Specify Fittingsizelevel to get a width that is as close as possible to the width value of
targetSize. - verticalFittingPriority:
The priority for vertical constraints. Specify Fittingsizelevel to get a height that is as close as possible to the height value of
targetSize.
Return Value
The optimal size for the view based on the provided constraint priorities.
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.