Home Ask Login Register

Developers Planet

Your answer is one click away!

Brad February 2016

Center 4 Images and maintain aspect ratio

Center 4 Images

I cannot figure out how to get these images to centre. I like how I got them resizing accordingly for each device but would like to have them sit in the centre. I feel like I'm missing something super obvious but after a week of daily 1-2 hour sessions of trying... I give up.

If the link (Centre 4 Images) to my screenshot works, you can see they are fitting to each device just fine, only not centred.

** The images left to right are 1, 2, 3, 4.


mohonish February 2016

Put the imageviews (1,2,3,4) inside a UIView (say ContentView) and give it two constraints - Top space to container, and Center horizontally in container. I'm assuming that you're imageViews are set up in such a way (having height, and bottom and top space to container constraints) that they would provide the height of ContentView.

That would help you center ContentView containing all the four images.

Hope that helps. Let me know if that works for you.

Post Status

Asked in February 2016
Viewed 3,164 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life