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 Mode
for theImageView
inSplashScreen.storyboard
- Mark
SplashScreen.storyboard
as 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.xcassets
orAssets.xcassets
) file. - In the content panel add
New image set
and 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.storyboard
file. - Add a
View Controller
to the newly created.storyboard
file:- open
Library
(+
button on the top-right), - find
View Controller
element, - drag-and-drop it to the
.storyboard
file.
- open
- Add an
Image View
to theView Controller
:- first remove other
View
element fromView Controller
, - open
Library
(+
button on the top-right), - find
Image View
element, - drag-and-drop it as a
View Controller
child in view hierarchy inspector.
- first remove other
- Set
Storyboard ID
toSplashScreenViewController
:- select
View Controller
in view hierarchy inspector, - navigate to
Identity Inspector
in the right panel, - and set
Storyboard ID
toSplashScreenViewController
.
- select
- Tick
Is Initial View Controller
inSplashScreenViewController
:- select
View Controller
in view hierarchy inspector, - navigate to
Attributes Inspector
in the right panel, - and tick
Is Initial View Controller
in View Controller section.
- select
- Configure
Image View
source:- select
Image View
in view hierarchy inspector, - navigate to
Attributes Inspector
in the right panel, - select
SplashScreen
inImage
parameter).
- select
- Configure
Background
of theImage View
:- select
Image View
in view hierarchy inspector, - navigate to
Attributes Inspector
in the right panel, - configure
Background
parameter:- To enter a
#RRGGBB
value you need to selectCustom
option and in theColors Popup
that appeared you need to navigate to the second tab and chooseRGB Sliders
from dropdown select.
- To enter a
- select
This is how your image will be displayed on the screen.
- Open
SplashScreen.storyboard
and selectImage View
fromView Controller
. - Navigate to
Attributes Inspector
in the right panel and locateContent Mode
. - Select one of the following:
Aspect Fit
to obtain CONTAIN resize mode,Aspect Fill
to 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
TARGETS
panel and navigate toGeneral
tab. - Locate
App Icons and Launch Images
section andLaunch Screen File
option. - Select or enter
SplashScreen
as 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 Set
and customize its values for different color modes:- in your
.xcassets
directory (either create a new.xcassets
for colors, or reuse an existing one e.g. with images) createNew Color Set
and name itSplashScreenBackground
, - navigate to
Attributes Inspector
in the right panel and changeAppearance
toAny, Dark
, - select desired color in
Attributes Inspector
in the right panel for each mode.
- in your
- Select created
named color
as theBackground
for theImage View
inSplashScreen.storyboard
:- open
SplashScreen.storyboard
and selectImage View
in view hierarchy inspector, - navigate to
Attributes Inspector
in the right panel, - configure
Background
parameter 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
SplashScreenBackground
Image Set
with desired background colors for each mode in yourImages.xcassets
directory:- open your
.xcassets
directory with images, - in the content panel add
New image set
and name itSplashScreenBackground
, - convert this
Image set
to supportDark Appearance
by navigating toAttributes Inspector
in the right panel and changingAppearance
toAny, Dark
, - provide images with colors for every mode (you can generate color 1x1px images using http://www.1x1px.me).
- open your
-
Update
SplashScreen.storyboard
to consist of a single top-levelView
with twoImage View
subviews (solid-colored image in the background and actual splash screen image in the foreground):- open
SplashScreen.storyboard
and replaceImage View
with a plainView
(searchLibrary
for 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
Image
toSplashScreenBackground
(prepared in previous step), - set
Content Mode
toScale To Fill
(color needs to take all available space),
- set
- make this subview take all available space in parent view:
- open
Add new constraints
bottom menu, - make sure
Constrain to margin
is not checked, - for every input, open the dropdown and select
View
(parent view reference) and set0
as the value, - once every side is covered (
0
value and parent view reference selected in dropdown) hitAdd 4 Constraints
, - observe that in
View Hierarchy Inspector
constraints are added andImage View
resized to take whole place of parent view.
- open
- configure attributes in
- Configure second
Image View
(actual splash screen image):- select second
Image View
and select correctImage
inAttributes Inspector
alongside 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 Inspector
in the right panel, - locate
Appearances
section and selectAny, Dark
, - provide image for
dark mode
by 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 hiding
flag:
- open main project view, select your project name from
TARGETS
panel and navigate toInfo
tab, - add or modify
Status bar initially hidden
attribute with desired value.
- Customize
StatusBar style
option:
- open main project view, select your project name from
TARGETS
panel and navigate toInfo
tab, - add or modify
Status bar style
attribute with desired value.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律