Class ContentSizeFitter
Resizes a RectTransform to fit the size of its content.
Inherited Members
Namespace: UnityEngine.UI
Assembly: UnityEngine.UI.dll
Syntax
[AddComponentMenu("Layout/Content Size Fitter", 141)]
[ExecuteAlways]
[RequireComponent(typeof(RectTransform))]
public class ContentSizeFitter : UIBehaviour, ILayoutSelfController, ILayoutController
Remarks
The ContentSizeFitter can be used on GameObjects that have one or more ILayoutElement components, such as Text, Image, HorizontalLayoutGroup, VerticalLayoutGroup, and GridLayoutGroup.
Constructors
ContentSizeFitter()
Protected default constructor. Use UnityEngine.GameObject.AddComponent<T>() to add a ContentSizeFitter to a GameObject.
Declaration
protected ContentSizeFitter()
Fields
m_HorizontalFit
Serialized backing field for horizontalFit.
Declaration
[Tooltip("Controls how the width of this RectTransform automatically resizes based on its content.")]
[SerializeField]
protected ContentSizeFitter.FitMode m_HorizontalFit
Field Value
| Type | Description |
|---|---|
| ContentSizeFitter.FitMode |
m_VerticalFit
Serialized backing field for verticalFit.
Declaration
[Tooltip("Controls how the height of this RectTransform automatically resizes based on its content.")]
[SerializeField]
protected ContentSizeFitter.FitMode m_VerticalFit
Field Value
| Type | Description |
|---|---|
| ContentSizeFitter.FitMode |
Properties
horizontalFit
The fit mode to use to determine the width.
Declaration
public ContentSizeFitter.FitMode horizontalFit { get; set; }
Property Value
| Type | Description |
|---|---|
| ContentSizeFitter.FitMode |
verticalFit
The fit mode to use to determine the height.
Declaration
public ContentSizeFitter.FitMode verticalFit { get; set; }
Property Value
| Type | Description |
|---|---|
| ContentSizeFitter.FitMode |
Methods
OnDisable()
Called when it becomes disabled. Registers for a layout rebuild.
Declaration
protected override void OnDisable()
Overrides
OnEnable()
Called when it becomes enabled. Registers for a layout rebuild.
Declaration
protected override void OnEnable()
Overrides
OnRectTransformDimensionsChange()
Called when the RectTransform dimensions change. Registers for a layout rebuild.
Declaration
protected override void OnRectTransformDimensionsChange()
Overrides
OnValidate()
Declaration
protected override void OnValidate()
Overrides
SetDirty()
If active, it marks this RectTransform's layout to be recalculated.
Declaration
protected void SetDirty()
SetLayoutHorizontal()
Resizes the RectTransform's width according to the horizontalFit mode.
Declaration
public virtual void SetLayoutHorizontal()
SetLayoutVertical()
Resizes the RectTransform's height according to the verticalFit mode.
Declaration
public virtual void SetLayoutVertical()