RectTransform的两个设置大小的api

 

var rtf = GetComponent<RectTransform>();
rtf.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 200);

SetSizeWithCurrentAnchors不会改变anchorMin和anchorMax

设置大小会根据pivot的值,往两边扩充

 

var rtf = GetComponent<RectTransform>();
rtf.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 640-50, 200);

SetInsetAndSizeFromParentEdge会改变anchorMin和anchorMax

设置大小时,Edge为Left往右边扩充,Edge为Right往左边扩充,Edge为Top往下扩充,Edge为Bottom往上扩充

 

posted @ 2023-07-30 14:30  yanghui01  阅读(18)  评论(0编辑  收藏  举报