I\'m working with a React Native app and I\'m trying to set a customize launch screen but I\'m not able to.
React Native creates a LaunchScreen.xib by default, so I\
Upon following the above solutions my app was getting stuck on the Splash Screen so I did the following 7 steps to add the custom splash screen on ios.
LaunchScreen.xib
file in your project (Notice that this is the screen which is shown by default in ios)Now we have to add the image to the Images.xcassets
so that we can reference it in the LaunchScreen.xib
to do that goto Images.xcassets
. click on +
button followed by import
and then add the image you want to show in the splash screen. Beneath AppIcon
you’ll see your image file name. This is the name we’ll use to reference in our LaunchScreen.xib
Now we have to reference the image we added in the LaunchScreen.xib
file so navigate back to LaunchScreen.xib
and click the image view
that we added earlier and on the right hand corner you will see bunch of options. click on first one that says image
and select the image which you imported in step 5
react-native run-ios
and you should see the changes.If you want to use the existing Launch Screen .xib file React Native initially has set up, but with your own logo and background color (and without any of the React Native default text), you can follow the instructions here: https://medium.com/@kelleyannerose/react-native-ios-splash-screen-in-xcode-bd53b84430ec.
If you create a Launch screen with the help of React then you should add the same thing in the LaunchScreen.xib file in iOS Xcode for that you can take a Screenshot and add it as an Image in the Images.xcassets.
Open LaunchScreen then add UIImageView in the View from Object Library from Right Panel in Xcode.
Add Trailing, Leading, Bottom and Top Constraints to the View. As Shown Below -
Don't Forget to change the UIImageView ContentMode as AspectFit so that it will look same when the app runs.
After That you need to add code in AppDelegate so that you don't get a white screen. The code is -
UIView* launchScreenView = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] objectAtIndex:0];
launchScreenView.frame = self.window.bounds;
rootView.loadingView = launchScreenView;
You can Refer - https://facebook.github.io/react-native/docs/running-on-device.html#pro-tip
Just for those still having trouble, there is one more step missing from the accepted answer before making the iOS Launch screen work.
Open Info.plist
in the project folder and delete "Main nib file base name" key. Then, rebuild and hopefully the issue is gone.
generator-rn-toolbox
is deprecated.
Use react-native-make instead.
I recommend generator-rn-toolbox for applying launch screen or main icon using on react-native. It is more simple and easy to use through cli as react-native.
npm install -g yo generator-rn-toolbox
brew install imagemagick
Apply splash screen on iOS
yo rn-toolbox:assets --splash YOURIMAGE.png --ios
or Android
yo rn-toolbox:assets --splash YOURIMAGE.png --android
That's all. :)
Source
For me on XCode 10.1
and react-native 59.2
I had to go through the additional steps after already adding the images, storyboard and 1 universal image.
Show in Finder
, then edit your Contents.json
fileImage should now be centered on all size iPhones (tested on Portrait).