FM/Assets/Scripts/Base/Helper/UIHelper.cs

21 lines
666 B
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using UnityEngine;
using UnityEngine.UI;
namespace Base.Helper
{
public static class UIHelper
{
/// <summary>
/// 限制Image尺寸在最大尺寸范围内等比例进行缩放
/// </summary>
/// <param name="image"></param>
/// <param name="maxSize"></param>
public static void LimitTheImageSize(Image image, float maxSize)
{
var rect = image.sprite.rect;
var max = rect.width > rect.height ? rect.width : rect.height;
var size = maxSize / max;
image.rectTransform.sizeDelta = new Vector2(size * rect.width, size * rect.height);
}
}
}