Creating a Launch Screen using a .xib
Although Storyboard-based launch screens are most favored by Apple, they can also be created using either a .xib. Regardless of which way you choose, you can now add, design, and create your Launch Screen inside Visual Studio for Mac or Visual Studio using the Xamarin Designer for iOS. For more information on creating a Launch Screen as a Storyboard visit the Launch Screen guide.
To create a launch screen using a .xib, do the following:
- Create and iOS single view project.
- Notice in the Resources folder that there is a LaunchScreen.xib file included by default:
We can open this .xib to edit it in the Designer, however let's create our own from scratch. Right-Click on LaunchScreen.xib to delete it.
- Right-click on the Resources folder and select Add > New File...
- Select iOS > Launch Screen and name it MyLaunchScreen:
- Double-Click to open MyLaunchScreen.xib in the iOS Designer.
- Delete the two labels that are currently in the View.
- Add a ImageView and a label to the View. You can set the image view to any image that you have added to your application. If you don't have an image, you can use one from the attached project:
- Set Constraints on the ImageView and Label. In attached example the constraints are set as follows:
- Top: top of View
- Bottom: bottom of View
- Left: Left of View
- Right: Right of View
- Top: Top of Image
- Bottom: Center of Image
- Left: Left of Image
- Right: Right of Image
- We now need to set this .xib file as our Launch Screen. This is done in the Info.plist. Open the Info.plist and under Universal Launch Images, set the Launch Screen dropdown to MyLaunchScreen:
- Run your app in the simulator. You should see that before it loads your app, it will display your .xib as a Launch Screen: