iOS: Auto-layout constraints acting strange when designing TableView for iPad - ios

I am trying to have simple custom table view cells with UIImageView and another View with three Labels in it.
I set the constrains to 5 from UIImageView and 0 from all remaining sizes. But as soon as I select bigger iPad in the Xcode designer (like iPad Pro or Pro with 12,9" screen) I suddenly get space on the right side even though the constraints still says "0" when clicked.
The screenshot below should help illustrate the issue (first is regular iPad, then iPad Pro 10.5" and finally iPad Pro 12,9"):
I already did some auto-layout work for iPhone and never encountered something like this.

Related

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

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

How To Fit UITableView in the screen with AutoLayout

I am trying to fill the screen with a TableView. I've tried pinning 4 edges but it broke when I view it in different devices (iPad Pro, iPhone SE, landscape and portrait orientation). The TableView is messed up for some reasons. It shouldn't be this hard to fill that in. Did I messed up some settings in my Xcode?
If you ran the application on a real device you'll find it as you expect it to be.
And if you opened another file then came back to storyboard you'll find the preview as expected too, I think it's a bug in the UI Builder.
Note: I'm using Xcode Version 8.3.2.

make iphone 6 app to fit iphone 4s screen resolution

I have developed an app for iphone 6. It works well on iphone 5 also but on 4s the bottom part is being cut off. Is there any way i can make the app to work for iphone 4s without using autolayouts.
This works well for iphone 6
But not for 4s, below is how it looks. The buttons are not visible.
Thanks for your answer
You can use UIScrollView instead of UIView & add all your inner control to Scroll view.
This will make Buttons visible all the time & Scroll the content.
Second Option, you can use AutoLayout. (which you dont want to use.!!)
Third , You can create a new design for iPhone 4s (if & only if u want the look exactly same as others)
-although, not recommended!!!
You can use UIScrollView instead of UIView & add all your inner control to Scroll view. Otherwise use UITableView
It will solve your problem.

iPad screen doesn't support autolayout

I have created view using autolayout it works fine in all iPhone devices but it left some blank space at left, right, top and bottom on iPad.I tried to make another xib specially for iPad which is 768*1024 but still facing same problem.
here is the screenshot of iPad output.
The problem is that you forgot to make this a universal app. So it is running on the iPad in emulation mode as an iPhone app in a reduced frame.

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