Auto Layout Issues Xcode 8 - ios

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.

Related

LaunchScreen.storyboard appearing differently on devices than in Xcode?

I am attempting to customize the default LaunchScreen.storyboard of my Flutter app. I simply have a red background on the default View, and I added an Image View as a child of it. This Image View is centered on the screen and renders an image that I have added to "Assets.xcassets" with all 3 sizes. Below is a preview of what my Xcode displays:
However, this storyboard renders differently on devices than it appears in Xcode. For example, it appears slightly off-centered on iPhone 12, and it is scaled up too high for iPhone 6s and is way off-centered. See below for screenshots:
As you can see, the storyboard renders differently on the two devices. How can I make the storyboard appear the same on both devices as it does in Xcode? Any help is appreciated. If I used any incorrect terminology or need to provide additional details, please let me know as I have minimal experience using Xcode.
From the storyboard screenshot attached, it looks like there are no constraints added to the UIImageView.
You should add top, leading, bottom & trailing constraints to superview with 0 spacing to achieve what you want.
UPDATE
Above is applicable to the case when you have a small size image like 100x100 or similar that can easily fit on all screen sizes. In the comments, we see that image is way too big and we want to keep it in center while occupying 50% of screen width.
Remove the leading and trailing constraints, select the imageView and it's superview - add equal widths constraint with a multiplier of 0.5, this will make sure that imageView will always occupy 50% of the superview's width.
Also add horizontally center constraint on the imageView. Make sure imageView Content Mode is set to Aspect Fit.

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.

Image Resizing for different screens XCode

I've been trying to find a solution to this problem for a long time but I haven't been able to solve it. How do I make an image appear smaller so it would fit the screen on a smaller device? When I have in on a larger device it fits fine but when switched to a smaller screen the images start to overlap.
Example of images overlapping
I would really appreciate the help. Thank You!
Use auto layout and set your Uiimageview aspect ratio to 1:1
There are a lot of ways. Some are mentioned below:
Using Auto layout
connect every image to side of main view and set their widths and height ratio 1:1 , also set their width proportional to main view widht.
using stackviews and autolayout
1st set images width proportional to main view width
then set their aspect ratio 1 : 1
then add the columns to 2 vertical stack views and add both columns to horizontal stackview.
set the left right and bottom constraint of final stackview
You can use auto resizing as well, but that is not totally reliable.
autoresizing is default behavior of view. In your case you have to set flexible width and height of each image

Autolayout UIImageview Swift

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.

launch screen xib not displaying imageview correctly

I'm using a launch screen xib and I can't get the image within the UIImageView to appear. Currently, I have a UILabel with the imageView placed right below the label and also centered horizontally. I set all the constraints for the imageView but for some reason the label appears but the image doesn't. This is my first time using the whole wAny hAny size classes. Is there something I'm missing?
Based on my recent experience, it appears that as of iOS 8.3, any images in the launch screen XIB have to be in the image assets. I do not know if this is the OP's problem or not, but definitely worth mentioning for other folks coming here with the same issue.
This is happening because of the horizontal space constraints of the imageView, both the leading and trailing space to the superview. Here the launch screen is laid out in the wAny|hAny size class. It could not satisfy the Horizontal space -(196) on a smaller device. So what you can do
Remove the horizontal space constrains(both leading&trailing) of imageView
Add widthconstraint to the imageView or Aspect Ratio could be more appropriate
Other constraints looks fine, top & bottom spacing and centre horizontally in container keep as it is

Resources