imgae =transform.GetComponent<Image>(); imgae.preserveAspect = true; float imageH = imgae.transform.parent .GetComponent<RectTransform>().sizeDelta.y; float imageW = imageH * imgae.preferredWidth / imgae.preferredHeight; RectTransform rectFransF = transform.GetComponent<RectTransform>(); rectFransF.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, imageW);
原文:https://www.cnblogs.com/zqiang0803/p/14707980.html