expo-splash-screen的IOS设置
see:https://github.com/expo/expo/tree/main/packages/expo-splash-screen#-configure-ios
npx expo install expo-splash-screen
Run npx pod-install after installing the package.
To achieve native splash screen (in iOS ecosystem it's called LaunchScreen) behavior, you have to provide either a SplashScreen.storyboard file or a SplashScreen.xib file, and configure your Xcode project accordingly.
The guide below shows how to configure your Xcode project to use a single image file as a splash screen using a .storyboard file (configuration for .xib filetype is analogous).
- Add an image to
Images.xcassets - Create
SplashScreen.storyboard - Select
Content Modefor theImageViewinSplashScreen.storyboard - Mark
SplashScreen.storyboardas the LaunchScreen - (optional) Enable dark mode
- (optional) Customize StatusBar
First you need to add the image file that would serve as a splash screen to your native project's resources.
- In your Xcode project open the
.xcassets(often namedImages.xcassetsorAssets.xcassets) file. - In the content panel add
New image setand name itSplashScreen. - Provide the splash screen image you've prepared (you have to provide it in three different scales).
This is the actual splash screen definition and will be used by the system to render your splash screen.
- Create a
SplashScreen.storyboardfile. - Add a
View Controllerto the newly created.storyboardfile:- open
Library(+button on the top-right), - find
View Controllerelement, - drag-and-drop it to the
.storyboardfile.
- open
- Add an
Image Viewto theView Controller:- first remove other
Viewelement fromView Controller, - open
Library(+button on the top-right), - find
Image Viewelement, - drag-and-drop it as a
View Controllerchild in view hierarchy inspector.
- first remove other
- Set
Storyboard IDtoSplashScreenViewController:- select
View Controllerin view hierarchy inspector, - navigate to
Identity Inspectorin the right panel, - and set
Storyboard IDtoSplashScreenViewController.
- select
- Tick
Is Initial View ControllerinSplashScreenViewController:- select
View Controllerin view hierarchy inspector, - navigate to
Attributes Inspectorin the right panel, - and tick
Is Initial View Controllerin View Controller section.
- select
- Configure
Image Viewsource:- select
Image Viewin view hierarchy inspector, - navigate to
Attributes Inspectorin the right panel, - select
SplashScreeninImageparameter).
- select
- Configure
Backgroundof theImage View:- select
Image Viewin view hierarchy inspector, - navigate to
Attributes Inspectorin the right panel, - configure
Backgroundparameter:- To enter a
#RRGGBBvalue you need to selectCustomoption and in theColors Popupthat appeared you need to navigate to the second tab and chooseRGB Slidersfrom dropdown select.
- To enter a
- select
This is how your image will be displayed on the screen.
- Open
SplashScreen.storyboardand selectImage ViewfromView Controller. - Navigate to
Attributes Inspectorin the right panel and locateContent Mode. - Select one of the following:
Aspect Fitto obtain CONTAIN resize mode,Aspect Fillto obtain COVER resize mode.
- You can always choose other options to achieve different image positioning and scaling.
The newly created SplashScreen.storyboard needs to be marked as the Launch Screen File in your Xcode project in order to be presented from the very beginning of your application launch.
- Select your project in
Project Navigator - Select your project name from
TARGETSpanel and navigate toGeneraltab. - Locate
App Icons and Launch Imagessection andLaunch Screen Fileoption. - Select or enter
SplashScreenas the value for located option.
Depending on what iOS version your application is targeting, you have to adjust your native project differently to a obtain working per-appearance splash screen view.
You can take advantage of named colors in your Xcode project.
- Create a new
Color Setand customize its values for different color modes:- in your
.xcassetsdirectory (either create a new.xcassetsfor colors, or reuse an existing one e.g. with images) createNew Color Setand name itSplashScreenBackground, - navigate to
Attributes Inspectorin the right panel and changeAppearancetoAny, Dark, - select desired color in
Attributes Inspectorin the right panel for each mode.
- in your
- Select created
named coloras theBackgroundfor theImage ViewinSplashScreen.storyboard:- open
SplashScreen.storyboardand selectImage Viewin view hierarchy inspector, - navigate to
Attributes Inspectorin the right panel, - configure
Backgroundparameter by selecting your creatednamed color(that should be listed asSplashScreenBackground).
- open
You cannot use named colors feature in your Xcode project. Instead you have to create an additional image set that contains small 1x1px images, each with the desired background color. Then, you'll use this additional image resource as a background in the splash screen view.
You can use this online generator to obtain 1x1px .png images with desired colors: http://www.1x1px.me.
- Create
SplashScreenBackgroundImage Setwith desired background colors for each mode in yourImages.xcassetsdirectory:- open your
.xcassetsdirectory with images, - in the content panel add
New image setand name itSplashScreenBackground, - convert this
Image setto supportDark Appearanceby navigating toAttributes Inspectorin the right panel and changingAppearancetoAny, Dark, - provide images with colors for every mode (you can generate color 1x1px images using http://www.1x1px.me).
- open your
-
Update
SplashScreen.storyboardto consist of a single top-levelViewwith twoImage Viewsubviews (solid-colored image in the background and actual splash screen image in the foreground):- open
SplashScreen.storyboardand replaceImage Viewwith a plainView(searchLibraryfor it and drag&drop it in place of currentImage View), - add two
- open
-
Configure first
Image View(background color):- configure attributes in
Attributes Inspector:- set
ImagetoSplashScreenBackground(prepared in previous step), - set
Content ModetoScale To Fill(color needs to take all available space),
- set
- make this subview take all available space in parent view:
- open
Add new constraintsbottom menu, - make sure
Constrain to marginis not checked, - for every input, open the dropdown and select
View(parent view reference) and set0as the value, - once every side is covered (
0value and parent view reference selected in dropdown) hitAdd 4 Constraints, - observe that in
View Hierarchy Inspectorconstraints are added andImage Viewresized to take whole place of parent view.
- open
- configure attributes in
- Configure second
Image View(actual splash screen image):- select second
Image Viewand select correctImageinAttributes Inspectoralongside with desiredContent Mode, - make this subview take all available space in parent view (see previous step).
- select second
You might want to add a separate image for dark mode. If the system is switched to dark mode, it would pick this different image instead of the normal one and present it in the splash screen view.
- In your Xcode project open
SplashScreen(created in previous section). - Convert this asset to support
Dark Appearance:
- navigate to
Attributes Inspectorin the right panel, - locate
Appearancessection and selectAny, Dark, - provide image for
dark modeby dropping it to the correct box.
If you're targeting a version of iOS < 11 then you cannot use named color feature and instead you need to generate images with desired background colors that are going to be used as the background for splash screen view. There is this awesome 1x1px png online generator: http://www.1x1px.me (use it to generate two 1x1px images with desired background colors for different color modes).
You might want to customize the StatusBar appearance during the time the SplashScreen is being shown.
- Customize
StatusBar hidingflag:
- open main project view, select your project name from
TARGETSpanel and navigate toInfotab, - add or modify
Status bar initially hiddenattribute with desired value.
- Customize
StatusBar styleoption:
- open main project view, select your project name from
TARGETSpanel and navigate toInfotab, - add or modify
Status bar styleattribute with desired value.


















浙公网安备 33010602011771号