How to Maintain Aspect Ratio Regardless of Screen Size

I’m developing a 2D game for iOS and I need a square panel in the meddle of the screen. How do I adjust the size of the square according to the screen size? The problem using anchors is that a square on iPhone becomes a rectangle on iPad.

You will want the canvas to Scale With Screen Size, but depending on your setup, horizontal and vertical anchors at the panel bounds will not work because screen ratio changes between devices and thus the panel will only be square for the aspect ratio you create the game in. If you need it in the middle of the screen, make sure you have the parent panel rectTransform transform set to full scale and then set the RectTransform of the panel you want to create a square with set to the middle/center point with position set to (0,0,0). Then set the size delta x and y to what you want and you’re good to go

Look into this one:

https://gamedev.stackexchange.com/questions/79546/how-do-you-handle-aspect-ratio-differences-with-unity-2d