UITransform Component Reference

The UITransform component defines the rectangle information on the UI, including the content size and anchor position of the rectangle. This component allows developers to modify the size and position of the rectangle freely, generally for rendering, calculation of click events, UI layout, screen adaptation, etc.

Click the Add Component button at the bottom of the Inspector panel and select UITransform from UI to add the UITransform component to the node.

Please refer to the UITransform API.

UITransform Properties

PropertyFunction Explanation
ContentSizeThe content size of UI rectangle.
AnchorPointThe anchor position of UI rectangle.
PriorityThe priority of UI nodes, sorted in the parent node. The order of the Canvas node is not affected by this property.

change the size and anchor point in script. Example:

```ts import { _decorator, Component, Node, UITransform } from ‘cc’; const { ccclass, property } = _decorator;

@ccclass(‘Example’) export class Example extends Component {

  1. start () {
  2. const uiTransform = this.getComponent(UITransform);
  3. // method one
  4. uiTransform.setContentSize(200, 120);
  5. uiTransform.setAnchorPoint(0, 0.5);
  6. // method two
  7. uiTransform.width = 200;
  8. uiTransform.height = 120;
  9. uiTransform.anchorX = 0;
  10. uiTransform.anchorY = 0.5;
  11. }

}