I am asking perhaps one of the easiest questions lol but just could not figure it out.
I have some view controllers created based on the screen size of iPhone 7, but when I change devices to iPhone 7plus and iPhoneSE, my labels and buttons were all misplaced...
I have uploaded what they look like in different devices, can somebody please help?
WhatItLooksLikeOniPhone7
WhatItLooksLikeOniPhoneSE
To keep the UI elements at a defined place you need to something that will keep the elements at their position. And hence you need to use autolayout.
Autolayout is basically a constraint based system which will layout the ui elements.
There are many tutorials available.
Related
I am starting a new project which should be working on every iOS device size possible.
The project is rather simple. The main view will be a scroll view and it will hold a '+' button (where it says 'button' in the image) in the top right corner. (It does not really matter, I'm just trying to give the general idea of what I'm trying to understand and implement.)
A small example:
What is the right approach for this kind of problem?
Should I create a different storyboard for each device?
Should I start creating an adjustable scroll view that will hold the needed buttons with some constraints (if at all possible)?
I have read this tutorial:
auto layout
which explains the auto layout nicely, but does not mention the issue I'm trying to figure out.
Any thoughts?
Use AutoLayout and position your views relative to one another (so no x pixels spacing between views). Make only one storyboard for all devices, when a different view should be loaded on another device (like a completely different layout), select the appropriate size class and adapt the views and constraints.
Then it will be recalculated on every device.
The storyboard has a preview section where you can choose a device to simulate the view on.
is there a way to have the view from interface builder in Xcode, be the same size as the iphone we use to test the app? The size of the viewcontroller seems to be 600*600. So when I move a UILabel somewhere to the left for example, it will be placed as if it was on the right on my iphone. Which is not easy to set the right constraints.
Do you have some tips to manipulate the items and place them easily? For now, I just align the item with the center point, and move it little by little.
The reason this happens is because of Apple's emphasis of size classes. It looks like a rectangle because whenever you are adding constraints and views, they'll be applied to every size class (i.e. horizontal/compact, vertical/compact, etc).
In english, it means it's applying those changes to run as such on any device.
To create constraints and views for just one size, you'll want to edit the size class you are working with. At the bottom of Xcode where it says "wAny hAny", click that and you can set what device you want to work with:
The whole idea of this is adaptive design, and I've got a post explaining it in more detail here.
The thing is that there is no one correct size for the iphone screen because there are so many different screen sizes. You can set the view size to anything you want in interface builder by clicking on the view and going to simulated metrics -> size but what you really want is autolayout so that your views fit properly on every device.
i have created a Storyboard where i create universal views for all iphones in portrait form. Simple views work just great, but as soon as you add different views and sub element something goes wrong. Can someone give me some tips what i am doing wrong?
I will be thankful for every kind of tips/advises how to get rid of this annoying view...
Have a nice sunday!
I found out the solution, the problem is that you can set all the measures in percent. But for to count all the sizes, XCode needs minimum 1 measure for width & height. If it gets the size of single element in your design, it can calculate all other sizes.
In my app I have a view for 4 inch screens in this way:
And then I want to reduce the size of my buttons when the app is running on an iPhone with a 3.5 inch screen, so I set my layout in this way:
but finally I obtain a view in this way
In this way the size of my button are ok but they are not aligned, so in this situation, what's the way to have aligned buttons?
thanks
Hi as per your question i've created demo similar to the layout for which you need the controls need to set. I've added images for single control and made video this using multiple controls to set the layout which you retrying to set.
link: https://www.youtube.com/watch?v=Nl2iMF0yKW8&list=PLXCowKcXAVgrxHKLWTa4HxNPrSmTj3D-_
Hope this will solve your issue.
I may not comment till I 50 posts, so here is the link. I had like the same problem some days ago. Just put all those in a parent view and center the parent view.
Link to my question/answer:
Top constraint won't get less with auto-layout
I am trying to lay out objects on a Storyboard using the interface builder yet when I run the app on an iPad2, the layout is being messed up and objects are not appearing where they should. All the objects are there but they are being moved horizontally and not the same number of pixels! For instance, I have two ImageViews overlayed on one another (one is 100x100 and one is 75x75 centred within) but when the app is run on the iPad, they are both being moved horizontally across the screen by different distances!
I'd like to add screenshots but unfortunately I can't for privacy reasons.
I know it's vague but does anyone have any ideas on where to start looking to fix this?
Thanks.
I had this problem too when I was first making an iPad app.
Try fiddling with some of the 'struts & springs' of the interface elements in the storyboard. To do this, select some of the interface elements, then on the right panel go to the size inspector and try some things with the 'Autosizing' rectangle.
Hope it helps!