简体   繁体   English

在 iOS 中 React Native 更改状态栏文本颜色

[英]React Native change status bar text color in iOS

I'm developing an app using React Native, I've been asked to set the text color of the status bar in white.我正在使用 React Native 开发一个应用程序,我被要求将状态栏的文本颜色设置为白色。

I used the StatusBar component with the property barStyle="light-content" and it works pretty well on Android but not on iOS, the text color is still black.我使用了带有属性 barStyle="light-content" 的 StatusBar 组件,它在 Android 上运行良好,但在 iOS 上运行得很好,文本颜色仍然是黑色。

I did some research about it but I couldn't find anything helpful.我对此进行了一些研究,但找不到任何有用的信息。 I even tried to select the Light Status bar style on XCode like the following picture shows but it still doesn't work我什至尝试在 XCode 上选择 Light Status bar 样式,如下图所示,但它仍然不起作用

I solved the problem! 我解决了这个问题! I use this code in Index page and set the text color to white: 我在索引页面中使用此代码并将文本颜色设置为白色:

<StatusBar  barStyle="light-content" translucent={true} />

Try putting this code in didFinishLaunchingWithOptions in your AppDelegate file. 尝试将此代码放在AppDelegate文件中的didFinishLaunchingWithOptions中。

UIApplication.shared.statusBarStyle = .lightContent

Objective c 目标c

 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

and in your info.plist file set UIViewControllerBasedStatusBarAppearance to NO 并在您的info.plist文件中将UIViewControllerBasedStatusBarAppearance设置为NO

I solved my problem ! 我解决了我的问题!

The issue came from a React Native library called React Native Navbar, it was taking control of the status bar as well, I had to setup the 'light-content' property in that component. 问题来自一个名为React Native Navbar的React Native库,它也控制了状态栏,我不得不在该组件中设置'light-content'属性。

<StatusBar backgroundColor={"white"} barStyle="dark-content" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM