Storyboard layout not correct on iPad 2 - ios

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!

Related

Buttons and Labels Not in Place

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.

Different iOS devices size programming approach

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.

interface builder : make the view the same size as the iphone, to know exactly what constraints to add?

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.

Universal Storyboard Preview - doesn't seem to work properly?

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.

UILabel in different position for 2 different screen sizes

I have a UILabel that i placed in the top left corner of the screen in the Storyboards. I disabled "Autolayout" and it works perfectly fine on the iPhone 5 screen. The problem comes when i try them on any of the smaller screens like the iPhone 4. The label is then placed on the bottom right corner. After this issue, i tried to programmatically 'fix' the position in the "viewDidLoad" method of the view controller, but it stills moves position and the problem continues.
Ive been scratching my head about this for a while!
Any help would be appreciated.
I would suggest that you turn autolayout back on. If you get the constraints right, this situation (two different screen sizes) is exactly the sort of thing autolayout is really good for. There's a very good reason why Apple migrated autolayout from OS X to iOS at exactly the moment the iPhone 5 screen appeared on the scene!
try to fix it at viewWillAppear
Go to the utilities panel, click the tab "Show size inspector", and change the autosizing. Then drag your component in your storyboard's view so that it stays in one of the "borders". If you do not need to support older iOS versions, I'd recommend you to figure the proper way with auto-layout though.

Resources