Para Para - 1 month ago 11
iOS Question

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:

Launch Screen.xib

What am I doing wrong? Why can't I see a menu like the following?

Size Constraints Menu

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.

Answer

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

Launch Screen Storyboard

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.

Launch Screen XIB