Autolayout views always same size on different screen sizes - ios

I have a view:
Can someone help me to layout these views that they all look the same on every iPhone? I mean size is dynamic and views shrink according to screen size.
I have tried aspect ration and other layout options but none helped.

if you want to change the view sizes on different screens using auto layout ,you have to add the height and width constraints .then only it changes view size.
Steps:
open your project in xcode.
goto storyboard choose Auto layout ,select your view ,
in Xcode From the Editor menu, choose Pin\Width and Height both
http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

As per your question please look at the link below it might help solving your problem of multiple views size and layout.
https://stackoverflow.com/a/27471120/4101371
you can also refer:
https://www.youtube.com/watch?v=Nl2iMF0yKW8&list=PLXCowKcXAVgrxHKLWTa4HxNPrSmTj3D-_
I've also added this link in the answer in above answer.

Related

How to change layout depending on screen resolution

I have issues with auto layout, when was presenter new iPhone my layout which was created for 5, 5.5, and at the 6.4 inch was locks not so nice.
Example iPhone XS Max:
iPhone 8:
So, how i can fix this, and this will locks nice?
Check your view constraint(bottom) It should be connect with Safe Area not superview
Form your question what I understand is that you want to distribute space according to screens.
I think you should divide cell layouts on to 3 parts and add controls of that part in to a views
then give all views equal height.
By doing this you will have full screen decided in three parts.
And at the end you can add constraints to controls which we added in view according to you requirements.
Note: Cell main content view height should be equals to screen height.
Hope this helps.

How to make auto layout resize labels and other objects based on screen size

What constraints would make this view resize the labels 1-9 with a smaller font and label size in order to keep labels 1-9 within the view. I have tried using minimum font scale and pinning the labels to all sides of the view. Any tips and or help with auto layout and building responsive UI's in Xcode are appreciated thank you.
iPhone 7 Plus screen size simulation
iPhone 4s screen size simulation
It's easy!
You can use constraints like this:
After adding all constraints you need check UILabel configuration:
If you have question - you can ask :)
I think here, you can find answer to your question (Part: Two Equal-Width Views).
A idea lies inside of using additional view between the labels and strengthening first and last labels to a top and a bottom edge of a parent view.
All you have to do is add some NSLayoutConstraints and change some UILabel Properties in the UIStoryBoard Interface Editor .. I have added an image and a gif for reference.
This gif image will give a detailed explanation :

iOS Auto Layout

I have the following view controller that I want to look great on all iPhones, I have been trying for hours and hours with the auto layout with no luck. The cats are buttons with the cat image as a background to the button. Can somebody tell me what should I do?
UPDATE: My goal is that there size adapts to the different iPhone screen sizes and they remain positioned this way. I tried setting 4 constraints from the 4 sides while not locking the width and the height and it looks bad. Help, please?
This is the image
You can use multiplier property of autolayout constraints to achieve this. Please share your xib file
Use size class for the different size screen with autolayout . It will resolve you problem.

How can I get my UICollectionView to be the same width as my device when using Auto Layout?

I created a UICollectionView in the storyboard editor and added it to my (custom) ViewController. Like every view controller in storyboard, it says the size is 600x600 and so the UICollectionView, which takes up the whole view, is also 600x600.
This is not correct though, as I am writing an iPhone app and so the real dimensions should be 320x568!
Because of this, when I add items to my collection, they are placed off the right side of the screen. For example, I first add a cell with an image in of size 160x213. It is left justified and it takes up exactly the left half of the screen. When I add the next image, there is a huge gap and it appears on the left side, partly cut off. The third image I would expect to appear below the first, but it doesn't appear at all. I believe it is off the right side of the screen. This implies that the size of the UICollectionView is 600x600 and not 320x568.
I should mention that I've tried everything I could think of to fix this. For example:
I tried adjusting the size of the collection view:
self.photoCollection.frame = CGRectMake(0, 0, 320, 568);
I tried unchecking "Use Size Classes" in the storyboard editor.
It seems to work if I uncheck "Use Auto Layout" but I would like to use auto layout. How do I get this work?
You can set the "Simulated Metrics" of the view in your storyboard like this below. Personally, I prefer using 3.5/4-inch to construct my layout, as with auto layout, i only need to add some constraints to elements and iOS will automatically support the 4.7 and 5 inch screen size.
I think you should google for some "Auto Layout" tutorials, and I don't think its too hard for you to pick up :D. For instance, if you want to set the collection view frame equal to your view frame. You can do it like this
Feel free to ask any follow up question if your have any, Cheers!

iOS orientation change resizing

I have read a lot of SO question about this already but nothing seems to work in my case. Simply when you add a UITableView and you test it and rotate the screen it will keep the width of the portrait orientation.
How can I make it so that it will always fill the screen's width for any screen size?
EDIT : My size inspector
Use the Autosizing feature in Storyboard for your UITableView. How to set it:
1.Select your UITableView.
2.Open the right pane -> Size Inspector:
3.Scroll down to the View section, here you'll see the Autosizing menu:
Don;t forget to disable Autolayout feature:
You're using AutoLayout in your XIB, so the AutoResizingMask stuff isn't your best route to success. You need to set the autolayout constraints on your TableView so that there is a 0 px gap between the leading (left) and trailing (right) sides of the TableView and its superview.
You can see from your screenshot that you already have some constraints in place, but they're probably not correct. I suggest you start by resetting all the existing constraints: I find that's usually best when I've got confused about where I am with constraints.
Select the top level view in your XIB file
Select Editor -> Resolve Auto Layout Issues -> Clear All Constraints in View from the menu
Select your TableView
Select Editor -> Resolve Auto Layout Issues -> Reset to Suggested Constraints from the menu
If that does the trick for you, I'd advise that you spend some time getting familiar with AutoLayout and review the constraints generated: you can select and edit them in the size inspector. This is also a pretty good tutorial.
For custom views, I often add my constraints programmatically as it's really easy to keep track of them - they're much more visible than when they're built in IB. I use a set of categories, provided by another SO user, that you'll find here and they make the code very easy to read and maintain.

Resources