Autolayout UIImageview Swift - ios

So,
I am trying to build an app from design, the design consists of 3 images horizontally on a portrait layout
Supporting Iphone 5 and upwards.
From this guide http://iosdesign.ivomynttinen.com/ the Iphone 5 should have 640px of horizontal space.
Each image is 100px by 148px high, therefore I have created added 3x UIImageview and laid them out horizontally.
Now without any constraints I get the following
If I auto constrain I get the following, same if I add constraints manually
Skips out the middle.
If I go to any any constraint , I get an error message in the logger.
This can be a vertical space to top layout constraint, just the one and it breaks.
I assume as images are only 100px wide, I should have plenty of room.
On the UIImageview I have done the following
Set Height and Width
Content is AspectFit
Clip Subviews Selected
Auto re-size selected
I have either not understood App design and the images do not fit, or have done some incorrectly with IB and UIImageview?
Any thoughts on this.
Sorry not a lot of code as it's all Interface builder.
Thanks

Sorry,
My own fault, "reset to auto constraints" and "clear constraints" had a bit of an issue, there was a bunch of constraints still kicking about when I delved in deeper.
In the end deleted then all and then manually added.

Related

AutoLayout problem when trying to display on iPads or smaller screens

I am trying to create an app with this UI.
I am facing a lot of problems because it's like a rhombus.
I tried to use a vertical stackView and these are my previews and my constrains.
I've tried to use aspect ratio(1:1.13 because they are not squares) to resize on all o the screens but on iPad its a lot bigger.
Is there a way to make it smaller on iPads?
I am new to auto layout so I am sorry if this question is not correct.
You're probably overthinking this. Instead of a stack view, create a "spacer" view and use constraints to center it and give it the correct height and width for all screen sizes. Test it. Now add the four squares, giving them correct height and width and positioning them in relation to the "spacer" view. Test that. Finally, hide the "spacer" view.

Auto Layout Issues Xcode 8

I've been working on an app page in the iPhone 7 view of the latest version of Xcode. I got everything working and looking well and then when I went to the iPad view, everything was stretched out and looked awful. I reseted the auto layout and added different constraints and nothing will work. The bigger the screen is, the more stretched out some of the images become, while other are perfectly good. What am I doing wrong and what can I do to fix this issue?
If your requirement is to keep the image in the middle I suggest that you don't use any of the pin constraints. Instead select the align constraints and align the image vertically/horizontally in the view.
What's happening here is that the images are pinned to the edges of the view and when you choose a wider device the images are stretched so as to maintain the pin constraints. That's not what you would want to do.
Hope this helps.
You might want to set the Content Mode of your ImageViews to Aspect Fit:
An Aspect Ratio Constraint is not needed. A Leading, Top and Center Constraint should be enough.
Add Aspect Ratio.connect image to view aspect ratio.next add the align constraints and align the image vertically/horizontally in the view.

Need to fix autolayout issues with only UIButton's and UILabels

Currently i am trying to use AutoLayout on my iOS app in xcode 6. The storyboard I am using consists of only UIButton and UILabel elements, which i would like to resize and fit based on the device. Everything works on the iphone 6 Plus and 6 but when I get to the 5S or 5 things get weird. I can't use size classes necessarily due to both 5s and 6/6P using compact width regular height. IS there a way to fix this?
all images can be found here
Yes! With autolayout there's always a way.
From those pictures it looks like you may have a vertical constraint on the "play" button that is attached to the top of the view. Try putting that constraint on the "How Long" label. That way the button position will be relative to the title instead of the whole screen.
Check to see that you have the following constraints :
Center all buttons and labels horizontally in the container (note,
this is 3 different constraints you need to set). You can select
all 3 at once and from the Align menu center them horizontally in container.
Constrain How Long to Top Layout Guide (Top Space to Top Layout Guide)
Constrain Play to How Long (pin vertical spacing)
Constrain Leaderboard to Play (pin vertical spacing)
Depending on how you want Leaderboard to float you may want to pin it to the Bottom Layout Guide instead of to play. The buttons and labels will then move according to your constraints.

Autolayout Rendering inconsistently across devices

I have a series of views each containing a scrollview wrapping various subviews i.e. Collection views, Labels, imagview. I am using auto layout for the first time and some views render fine on some devices but not on others, I have attached previews of views on iPhone 4s, 5, and 6.
In particular I am not sure how the alignment of the History views appears off centre in iPhone 5 and 4 but fine in 6, and the collection view in iPhone 6 appears cut sort on the right side but not for iPhone 5,4, and lastly how the blue image with label 'Image Title' on top of the zoomable image on iPhone 4s appears to be cut short. I would of thought a error in autolayout would of been consistent across devices ?
Any input appreciated.
It looks like you're setting absolute widths on some elements. Instead you should be setting distance to the parent UIView's edges. I.e. trailing/leading space to container.
Try to give consistent constraints. Looks like you are just doing leading and top space to superview and maybe you are adding width and height constraints to avoid misplaced views. Try to think like you are doing autoresizing masks before autolayouts. Either try to keep ratio or expand with the container with trailing and bottom space constraints.

ios - UIScrollview w/ autolayout on Xcode 6

I have been struggling for days with this implementation, and even though I have tried to do every tutorial I found on the web, I still cannot make things work the way I want.
Basically, I am trying to put my login form in a scrollview, so that it takes the whole screen at first (and on all iPhones / iPads), and if the keyboard appears everything should move. The problem IS, my view doesn't take the whole screen... Either it is too large, or too high, even though in Interface Builder everything seams correct (from layout to constraints). Below and image of the layout I want to achieve (I am using an universal storyboard, with Size Classes and Autolayout enabled):
http://img4.hostingpics.net/pics/829115app.png
Can someone point me out on achieving this layout ?
Thanks in advance.
I would suggest pinning top, leading and trailing spaces of your scroll view to its superview. And set a bottom space constraint less or equal to the keyboard's height if you set it to 0, the scroll view won't be able to resize.
With your form layout set vertical center constraints and top space to superview constraints for your top label being more or equal than the distance you set in the IB, and then you can set relative space constraints between each of the components.
Hope I answered your question.
Edit: Just the provided project and got it working. I think the problem is caused by it being a containerView inside a scrollView. And both the container and the scrollViews content view adapt to the size of its subviews. Because of that, setting relative constraints won't help.
What I did was to set an explicit size (screen's size) to the containerView and setting setTranslatesAutoresizingMaskIntoConstraints(true) to it.
I modified your project and uploaded it here

Resources