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:
LaunchScreen.xib
LaunchScreen.storyboard
(Menu: File > New > File > iOS - User Interface - Storyboard
)LaunchScreen.storyboard
in the "Launch Screen File" combo boxLaunchScreen.storyboard
, add a View Controller, and make sure to tick the "Is Initial View Controller Box"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With