Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode center image while keeping square

Tags:

xcode

swift

Swift/xcode newbie here, be gentle.

I'm trying to set an image to be squared (around 160x160px) in the center of the screen on iphones and ipads.

Is there a way to set the coordinates per device. or any method around this?

constraints just scretch the image out.

like image 875
Trevor Wood Avatar asked Oct 30 '25 22:10

Trevor Wood


1 Answers

I'm pretty new to Xcode, but I've recently learned about auto layout / constraints.

Select your image view and apply width and height constraints via the pin dialogue box (screenshot below), then open your alignment constraints and select center horizontally and center vertically. Then just apply your constraints and voila!

Like I said I'm still learning so if this is wrong, anybody please feel free to jump in.

enter image description here

enter image description here

like image 148
Nick Winner Avatar answered Nov 02 '25 13:11

Nick Winner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!