RectTransform
1.在项目中使用动态生成UI项目时要手动设置RectTransform,否则可能出现位置偏移的情况。
//设置Top的值为0
GetComponent<RectTransform> ().offsetMax = new Vector2 (GetComponent<RectTransform> ().offsetMax.x, 0);
//设置Bottom的值
GetComponent<RectTransform> ().offsetMin = new Vector2 (GetComponent<RectTransform> ().offsetMin.x, 0);
//设置宽和高
GetComponent<RectTransform> ().sizeDelta = new Vector2 (0, 0);
//改变坐标
GetComponent<RectTransform> ().anchoredPosition3D = new Vector3 (0,0, 0);
//设置锚点
GetComponent<RectTransform> ().anchoredPosition = new Vector2 (x, y);