Xcode 'Deletes' Image View Inside Table View Based On Device Screen Size - ios

I'm creating a simple app that includes a table view using Swift 5 and Xcode 11. Inside the table view(which, by the way, is fixed into landscape), there is a button on the right of the tableview cells and an image view with fixed constraints, size, and width on the left. Everything has been working out pretty well for my app, until I noticed that the image view would kind of 'disappear' if I changed the device to, for example, iPhone 5s, 4s, or even iPhone Pro(I'm testing with iPhone 11 Pro Max).
This is when the device is iPhone 11 Pro Max:
11 Pro Max
This is when the device is iPhone 11 Pro: 11 Pro
And here are my constraints for my image view: Constraints
Any help is appreciated
P.S. Ignore the image view that says 'img'

After seeing both of the screen shots and the constraints I see what is the issue here.
It's the way you have applied the trailing constraint for the image which in your case is 663 (Should not be fixed). What you can try is Give width constraint to the image view and then change the trailing constraint something like below
This should help you.
Also what you have to take care of moving forward is the constraints you choose to apply coz that is the most important thing while desigining Responsive UI
Happy Coding.

right Constraint should be negative,for example,
img.snp.right = view.right - 20

Related

Xcode 8 AutoLayout/Constraints: Changing view to fit each Iphone screen size?

I am new to Xcode, and have been trying to figure out how to use AutoLayout and constraints. Long story short, after I hit 'add missing constraints' the Iphone 7 screen looks just as I intended, but both the Iphone 7 plus and Iphone SE screens look completely screwed up. What can I do to fix this so that every screen looks like the Iphone 7?
Iphone 7
Example Iphone SE (screwed up)
add missing constrains option means: adds the constraints needed to have a nonambiguous layout. may not work well for all iOS devices, and may not work well for device's rotation changes or view size changes, so, check view's constrains in size inspector panel
for more info:check Apple's auto layout guide

Layout missed up on 3.5" Screen iPhone 4

I have developed my App on XCODE 8 which by default removes iPhone 4 emulator and I didn't notice that until I finished my app, and I used Auto layout to make the UI fits all iPhone screens and that what happened (the layout was good on iPhone 7,6,5) the problem is when I additionally installed iPhone 4 emulator I found that the layout is totally missed up and unreadable/usable.
So what options do I have to solve this and make it fit the iPhone 4 screen too with Auto-Layout with missing up the other sizes ?
Here is screen shot of my Login screen on iPhone 6 (4.7") vs iPhone 4 (3.5")
You must always give constraints with respect to other alternative buttons or a view, it should not be hard coded. Try making views programatically, it will be more easy and helpful to you.
It seems like your constraint is set to have a fixed distance related to the top of your screen. So when the screen height get smaller, your views are pushed out of the screen. So to better adjust views position, you can have your views to be related to vertical center. Say your login box is in both horizontal and vertical center, not metter you are using iphone 6 or 4, you should always see your login box.

Horizontal space constraint not working in iPhone 6 Plus only?

So I'm porting my app to adjust for various devices (iPhone 4/4S, iPhone 5/5S, iPhone 6/6P). My app only operates in portrait mode so the constraints and such should be very easy. I have been leveraging the new Xcode 6.2 tools such as the preview tool, and inferred view controller size, so I only have one storyboard for every device. However I have set up all the necessary constraints and the app runs and looks great on all the devices, excluding the iPhone 6P. But what confuses me is that the preview for the iPhone 6P looks exactly what I want, however when I run in the simulator its not correct. Please looks at the images below to understand the problem fully.
The desired look is this: (what it looks like running on all devices except iPhone 6P)
Now what it looks like on the iPhone 6P: (as you can see the tableview is shifted (on both sides) inward.
However as seen in the storyboard, the preview shows it correctly:
This is what the constraints look like in the storyboard:
Hopefully you can understand the problem by now and hope you can offer some help, thanks in advance, feel free to ask for clarification.
As you have confirmed in the comments the issue is that you are constraining to the view margin instead of the view directly.
To stop constraining to a margin for an existing constraint, select it and in the Size inspector uncheck the Relative to marginfor the items.
When creating a new constraint by dragging with control key, holding the alt (option) key while creating constraints will toggle the margin option.
If you are creating it with the popup menu in the lower rigth just uncheck the Constrains to margin

Developing for IPhone 4s, 5, 6 and 6+

I've been working on a specific app for a while now and everything was good. But upon all this news of the iPhone 6 and the new Xcode, everything has just become confusing. Using Auto layout and designing for the iPhone have just become the most complicated thing to do. Every time I add constraints my images just triple in size. When all I want is to resize them to fit rationally across all the iPhone platforms(In portrait mode). For example I would like for certain images to grow as I work From the iPhone 5 to the 6+. Does any one know how to do this?
What do you mean triple in size?
Easiest way to have an image view scale is do the following:
Add it as a subview to the view of your view controller
Pin it at the top, left and right, leaving height unconstrained
Add an aspect ratio constraint, so that it can automatically calculate its height based on the width it gets

How to make controls in view not overlap if built by Interface Builder for Xcode 4.5 and iPhone 5?

I am using Xcode 4.5 and iPhone 4 and 5 simulator, and the Interface Builder would add a UIButton in the top half of the screen with a top constraint, and add a UIButton in the bottom half of the screen with a bottom constraint.
It works fine on an iPhone 5 simulator, but on the iPhone 4 simulator, the buttons can overlap, or the bottom button may even get positioned above the top button.
I think it is due to the constraint, such as the bottom button "must be 250 points away from the bottom margin". I can't delete the constraint, and if I change it to "250 points or less", it won't work, if I change it to "250 points or more", it won't work either.
Is there a way to:
1) Make it have no constraint, but just position at absolute x and y? (or what about the spring in the past, so that everything is more spaced out in iPhone 5?)
2) Make the NIB into a one for iPhone 4 and 4S only, so that the app works well on iPhone 4 and 4S and just "black barred" on the iPhone 5.
3) Make it work well on iPhone 5 and work well on iPhone 4 as well?
If you know solutions to only (1), (2), or (3), above, please give it regardless, as it is still a viable solution for the transition period.
It is actually very easy to reproduce: Create a simple Single View app using Xcode 4.5, and drag one button just above the center point of the screen, and another one just below the center point of the screen. Then run it on the Simulator. On iPhone 5, it is:
And now stop the app, and change the Device in the Simulator to iPhone 4S (3.5 inch Retina). If you don't stop the app first, the Simulator can crash. Now run the app again, and the buttons will overlap:
I had the same problem, and it was due to a wrong settings for autosizing. To change the autosizing, click on the control in the interface builder, go to the size inspector.
Notice the bold red I's in the autosizing grid, they control placement when the screen is resized (like when going from iPhone 3GS to iPhone 5.
I think it will work best for you if you make your autosizing look like this:
I'm not sure, since I haven't used constraint-based layout (and won't until we drop support for iOS 5). Traditional NIB-based autoresizing will do absolute coordinates.
You can't do that for just one screen, as far as I know — you can disable it for your whole app by removing Default-568h#2x.png.
I'd go for programmatic layout, or if you want the easy way (which will be a pain to maintain), different nibs for different screen sizes. Note that you'll want to correctly handle the in-call status bar too...
EDIT: Put the two buttons in a container view and make the constraint center the container inside its parent? It won't adjust the spacing between buttons, but should look okay on both devices.
Select your buttons and add "vertical spacing" constraint for them. And set "less than" for top/bottom margins.

Resources