Aastha Aastha - 28 days ago 17
iOS Question

How to setup layout constraints for a horizontal alignment of UIImageView's

I am trying to implement something like the image shown (http://i.stack.imgur.com/jKmGO.png) below using auto layout in Swift, but every time I end up with some issues. Can anyone please tell me the best way to implement auto layout for this kind of arrangement in horizontal grid for 3,4,5 or more image views.

Answer

Try the following steps 1) first select all of them and add constraint EQUAL WIDTH to images 2) set the leading space between left margin and first image view( let it be d) 3) Similarly set trailing space between the right margin and last imageview (let it be d) 4) Now add constraint HORIZONTAL DISTANCE(d) between all the image view e.g.

LEFT MARGIN-d-IMAGE1-d-IMAGE2-d-IMAGE3-d-IMAGE4-d-RIGHT MARGIN

Checkout Stanford Cs193p lecture no 8. Something similar is considered which was a basic calculator with equal width and height of keys.

Comments