I am trying to get into the Auto Layout business, but i find it kinda hard.
I am trying to get 5 image views to display next to each other in the center of the view. They need to resize themselves to expand their height / width as well.
This is how it looks in IB (and kinda the way it needs to look when running the app):
So i have the following constraints:
However, when i run it, it looks like this:
And i am just kinda stumped here. What am i doing wrong?
Thanks in advance, Best Regards - /JBJ
** EDIT ** I added a trailing constraint to the last button. This makes sure they are all within the screen, but is kinda problematic when thinking about the size of it, so that didn't solve it either.
* EDIT EDIT * Tried removing the top and bottom constraint since they are the ones forcing the size up. Added a vertical center constraint to them all. This won't work either. Displaying them very small (lined up nicely, but too small) and also comes with warnings:
There are three main types of Auto Layout issues: ambiguous layouts, unsatisfiable constraints and logic errors.
Auto layout is a property you can add to frames and components. It lets you create designs that grow to fill or shrink to fit, and reflow as their contents change. This is great when you need to add new layers, accommodate longer text strings, or maintain alignment as your designs evolve.
Use the keyboard shortcut ⇧ Shift ⇧ Shift A to add auto layout. Figma will create a frame around your selection, and add auto layout.
OK, here goes...
Make sure you update the frames once you're done to reposition the buttons to their new constraints...
The preview screen shows this working at all different sizes...
For placing them at the centre of the screen vertically use
NSLayoutConstraint *constraintHorizontal = [NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self.superview
attribute:attribute
multiplier:1.0f
constant:0.0f];
For placing them horizontally Button width = (width of the screen)-(button spacing dimension)- (left distance)- (right distance)/5;
Same for height. Initial left constraint for the first image view will be left distance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With