iOS Auto-Layout Max-Width - ios

So I'm trying to build a view that obeys the following. On smaller screens, the view will match the trailing and leading constraints to consume 100% of the width excluding the 32px margin. On larger screens, the view will not exceed a width of some constant, let's say 480px.
I've looked into it, and I tried setting the trailing and leading constraints to have a lower priority than the <= width constraint, however, on screens smaller than 480 pixels for example, the view will expand beyond the bounds of the screen. Essentially, I'm trying to use auto layout to use 100% width with 32px margin up to 480px. How do I fix my constraints?

Related

Increase aspect ratio according to screen size- iOS

A view at the bottom of a view controller with the following constraint:
leading - 0
trailing - 0
bottom - 0
aspect ratio - 7:1
it looks good on small screen sizes, but on larger screen the view looks too small. What is the best way to increase the aspect ratio according to what screen is using the application
Instead of having aspect ratio set, use proportional height and proportional width. To do so:
1- Select your view and set its height equal to the height of its superview
2- Click Edit and then change "proportional" to whatever you want:
Now you have a view that will be proportional to its superview height. Do the same for its width if you need it.
To be more precise, you can play with the priority of the constraint. For instance keep your ratio constraint and set its priority to 999.
Then change both proportional constraints (those we just add) constant to ">=" instead of "=". Then try different values of multiplier to see how the view react. By doing this you might need a maximum height/width constraint as well (as the view won't know in certain cases which size to choose).

Set max width to constraint

I have rectangle with four constraints. All works ok, but on ipad this rectangle is too big. So is there a way to set max margin for constraints. i tried set Relation value to "gather then" or "less then" but it not works.
Constraints have a field for priority. This is a case where you want to use that. It looks like you want your rectangle to be centered, so I would recommend the following constraints:
CenterX of rectangle equal to CenterX of superView. Priority 1000
CenterY of rectangle equal to CenterY of superView. Priority 1000
Width of rectangle less than or equal to maximum size you want for iPad. Priority 1000
Height of rectangle less than or equal to maximum size you want for iPad. Priority 1000
Vertical constraint for distance from top of superView. Priority 750
Horizontal constraint for distance from leading edge of superView. Priority 750
On iPhones, all of the constraints will be met because the rectangle will easily be smaller than the maximum size for iPad.
On iPads, the higher priority width and height constraints will keep the rectangle from growing too big, and Auto Layout will allow the top and leading edge constraints to be broken to make that possible, but it will make the rectangle as big as possible to come as close as possible to meeting the horizontal and vertical offsets.

iOS: Constraining View with fixed aspect ratio to trailing edge OR bottom edge

I have an ImageView that is constraint to be a square and on its top edge:
http://i.imgur.com/dACmwPN.png
The problem is that I want the view to fill the entire bottom space without exceeding the superview. In other words it should conform to either the width or the remaining height depending on which one is smaller.
The guide I am following suggests to add all of these to a stack view, but that is an iOS 9 feature and I want to develop for iOS8. What would be a good solution for that SDK?
I would add width = height constraint to keep the aspect ratio, then bottom and trailing constraints with lower priority (900) and >= margin value (ex 8) . This way image will be a square and it will not go over bottom or right. Also aspect fit should be set.

Autolayout bottom spacing constraint is not obeyed

I have a UIButton and a UILabel constrained to be a standard distance from the bottom of the Superview. Works well on the iPad, but on the smaller iPhone screens, when other elements take up too much space, these views are pushed off the edge of the screen despite their constraint to remain a standard distance from the bottom. Why is this so?
What I would like to have happen is for the four rectangles to shrink in size so that there is still room for the "Go Back" and "Question" label to remain a standard distance from the bottom. The four rectangles can maintain aspect ratio and equal width/height by all shrinking at the same ratio. I have no constraints on their needing to be equal to or larger than a certain size. I've tried lowering their Content Compression Resistance Priority as well.
Configuration:
(I have also tried "equal" and "<=" in top spacing between "Go Back" & bottom left rectangle)
("Greater than or equal" works best on iPad to keep "Go Back" at the bottom of the screen)
How it looks on iPhone 6 and iPhone 6+ - with the labels cut off at bottom:
Did you try to lower those four buttons' height constraint's priority??
For example like this, try to set them to 750
You can make this work with a couple of changes and additions. Give the leading and trailing constraints between the top 2 rectangles and the superview a lower priority (I used 749), but still keep them as "equal". This will keep them at the standard distance from the edges if it's possible, but will allow them to have a larger spacing if the vertical space combined with the aspect ratio requires it. The problem with this, is that since they aren't required any more, when those constraints need to stretch, there's nothing that says they have to stretch equally; therefore, we need some way to keep the rectangles centered. So, instead of a spacing constraint between the left and right top rectangles, add a small view (I used 8x8) that has a centerY constraint to one of the rectangles, and zero constant spacing constraints to the two rectangles. Give this view a centerX constraint to the superview; this construct will give you the same spacing between your rectangles that you had before, but will keep them centered in the superview while allowing them to shrink in width (and height to keep the aspect ratio) if need to accommodate the vertical space.

iOS Auto-Layout Stretch to Fill

I would like to take 4 square UIImageViews and align them from left to right at the bottom of a view. I want the images to grow in height (with the correct height/width aspect ratio) and have no spaces between the images. I want all the images to be of equal width
I seem to be having a hard time coming up with the proper constraints.
I've set all the images to Aspect Fit. I've created 8 constraints on all 4 images to have equal widths and height. On the far left and far right I've set the training space to the view as 0. I've aligned them all to the bottom of the view with a constraint of 0 as well.
This all seems to work... except that the images only grow in width and not height. I'm
hoping that as the width is calculated the image will grow proportionally in height. Any ideas?
PS: I would like to do this in Interface Builder if possible, but if code is needed, that's fine

Resources