unity 设置UI宽高

//获取UI宽高(只读)
float width = rtf.rect.width;
float height = rtf.rect.height;

    **设置UI宽度
    //rtf.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100);
    设置UI高度
    //rtf.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100);**

    **//rtf.sizeDelta = new Vector2(100, 100);
    //当前物体大小 -  锚点大小
    //如果锚点不分开,结果是物体大小
    size = rtf.sizeDelta;**

你可能感兴趣的:(笔记)