Xcode iPhone simulator acting funky - ios

I have just begun an iPhone app tutorial. What shows up in my storyboard is starkly different to what shows up in the iPhone simulator:
One shows the "Hello World" message as being on the left
The other shows it on the right
The window is maxed out, so it's not just a viewing error. Any suggestions?

I think you should start learning Auto Layout and after that add some constrains to your label

What you want to do is got to View > Utilities > Show the attributes inspector Under Simulated metrics change the Size (which is Inferred by default) depending from what you want..
Note: Make sure you have selected your view controller, see the image...
for dynamic approach..
Make use of your autolayout and set constraints..
at the bottom right of the storyboard click Align and set your prefered Alignment Constraints..
I'm out here, Cheers to you sir..

The location of the label is the same if you don`t use autolayout correctly.
Select the label and add the constraint, you can play with these and auto adjust the frame.

Set your layout to compact width | regular height

Ok two things i want to tell you here !!
What you see in storyboard is not what gets rendered in simulator !, the storyboard is just for your visual assistance , but if this is puzzling you , do one thing go to storyboard ->identityInspector(top right side panel) select 4th tab -> simulated Metrics ->size (click on it and find the one simulator on which you are running).
2nd thing ->
if you want the frames be adjusted as per changing resolution ,you better make sure to use autolayout and set appropriate constraint .

Related

View doesn't fit in iOS Simulator

This must be a dumb question, but nevertheless I ask it. I don't have to explain (I think) that I'm just beginning with Xcode.
I have created this view in IB:
And this is the result in the simulator:
What can I do to fix this. It doesn't matter what device I choose (eg. 4S or 6) and device options are in sync (= same in IB and simulator).
NB: It is a new project and I have reset the auto-layout constraint to suggested settings.
You need to ensure your Auto Layout constrains are accurate.
Make sure the view a controller is selected, and choose "Clear constraints"
Select each of these items and choose "center horizontally in container"
Select each of these, and add a constraint linking each to the one above. Note Xcode will fill in their current positions as default values.
Auto Layout tip: name your items in the document outline (the left in IB). Then when you examine constraints, you will be able to see which ones they are attached to by looking in the size inspector in the right.
Watch this video and get familiar with Auto-Layout.
https://www.youtube.com/watch?v=G53PuA_TlXk
Letting Xcode use "suggested constraints" is nearly always useless and won't work like you expect. So you'll either need to position all of your elements programmatically by changing their frame, or, you need to set up proper auto-layout constraints.
Your problem is that you are not using Autolayout functionality. I Would recommend reading about it, especially if you are new to iOS Dev. You really can do a lot if you are using IB (Storyboards) - check out this tutorial is should get you started
Autolayout is a system that helps you create apps for all different device dimensions.
You need to go into attributes inspector for the view controller (right sided panel) go Simulated Metrics(should be at the top) -> Size and change it to "iPhone 4S" or "iPhone 5".

iOS 8 swift application, content not centered

Everytime I run my iOS application, everything is off-centered. In this screenshot, you can see that the text seems a little off, and the black box is definitely not vertically centered along the page, although the text and box are centered according to the storyboard.
simulator screenshot
storyboard screenshot
I am guessing that the issue must have something to do with the size settings on the bottom of the storyboard. I am using wCompact and hAny.
Any help would be appreciated so that all this will look centered properly.
This is probably because you don't have your constraints set. You can click on the UIImage or UILabel and go to Editor -> Resolve Auto Layout Issues -> Add Missing Constraints (For All Views) if you want to use Auto Layout. Otherwise, look up some constraint tutorials and you'll have to set them manually. It's not too bad once you get the hang out it!

Launch image adds margin

After adding my launch image using a xib (and I even tried the traditional launch image way as well) some of my view controllers have a strange right margin now. For example before I might have had a label whose width was the entire screen, and used auto layouts such that it was leading/trailing to the content margins, and now despite that after adding a launch image there is a margin (it's not on every screen, but definitely some). On one of my screens where this is most prevalent i'm using autolayout but overriding with constraints that I add programmatically. Not sure if that's related.
Has anyone experienced anything like this or does anyone know if adding launch screens affect the story board / view controllers in any way?
Thanks!
On the launch screen select your image view, then select the pin at the bottom right of xcode (3rd option). Make sure all constraints are set to 0, while making sure the red I is selected for each one when they are set and uncheck constraint to margins. Finally click add constraints :)
Hope this helps you!
Rachel

Launch Screen XIB: Missing Width / Height Constraints (Xcode 6)

Using Xcode 6, I am building an iOS app that targets iOS8.
I'm working on a LaunchScreen.xib file, created from the menu: File > New > File > iOS - User Interface - Launch Screen. "Use Auto Layout" is enabled.
Inside the XIB's main UIView, I've placed a UIImageView. I would like to add width and height constraints, so that the UIImageView has the same size as the container. However, Xcode doesn't let me do that: I can only work with spacing and alignment.
Here's what I see:
What am I doing wrong? Why can't I see a menu like the following?
I know I could reach the same result by setting leading space, trailing space, top space, and bottom space to container to 0, but I would also like to understand what's happening here.
EDIT:
Xcode 7+ defaults to a Storyboard file for the Launch Screen.
As explained below, unlike XIBs, Storyboard files allow you to set width and height constraints to the root UIView.
I haven't been able to find an official explanation as to why XIBs behave like that, when they have a UIView at the root.
What looks weird to me is that what we are provided with as a default (LaunchScreen.xib) isn't set up to behave exactly like the Storyboards we've got used to.
The first solution I opted for was using a Storyboard to draw the Launch Screen, instead of a XIB:
Delete LaunchScreen.xib
Create a LaunchScreen.storyboard (Menu: File > New > File > iOS - User Interface - Storyboard)
Go to your project properties, select navigate to your target's general properties and select LaunchScreen.storyboard in the "Launch Screen File" combo box
Open LaunchScreen.storyboard, add a View Controller, and make sure to tick the "Is Initial View Controller Box"
You can now work on the View Controller's View as your Launch Screen, and you'll get the width and height constraints I was initially looking for
An alternative solution is removing the default UIView in LaunchScreen.xib and replacing it with a View Controller.
Just like in the previous case, if you do so, you can work on the View Controller's View, and you'll get the usual constraint menu.
That happens for every .xib, you just can't make a view of equal width than the main view. On the other hand it is possible to do it when you are in a story board.
Finally as you said you can accomplish the desired layout by setting the leading, trailing top and bottom distances.
Will your app run on a single device? If not how do you know the size of the container? It will vary between an iPhone 5, iPhone 6, iPod or iPad. The best way is still to specify leading space, trailing space, top space and bottom space to 0. You're sure it will work on any device.
Anyway, I tried to reproduce the problem, but I am able to specify the width and height of the image view when going in the Pin menu whether in Editor/Pin or by pressing the button at the bottom of the editor. I can specify any width/height with no problem.
Hope that helps!
A very simple solution is to add a clear UIView and pin it to the container, then you can access all the constraints by associating them with the clear "root" UIView you have added.

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