2

I'm trying to change the font color of the status bar in one of my modal views to white. The other views are set to be white in the app delegate.

I've tried the following code found in an answer to a similar question in the ViewController.

 - (UIStatusBarStyle)preferredStatusBarStyle {

    return UIStatusBarStyleLightContent;
}

but that does not work since the font still appears as black.

Fairly new to the iOS scene, please help with any suggestions.

4

2 回答 2

1

您需要结合使用当前代码并将View controller-based status bar appearanceInfo.plist 中的键设置为 YES。

不过,这里缺少的一块拼图是,您还需要告诉 iOS 您想要更新状态栏:

- (void)setNeedsStatusBarAppearanceUpdate;

这是 UIViewController 上的一个方法。像这样调用它viewDidLoad

- (void)viewDidLoad
{
    [self setNeedsStatusBarAppearanceUpdate];
    ...

请注意,它仅适用于 iOS 7,并在 iOS 6 及更低版本上引发异常,因此在我的所有项目中,我都有#define这样的:

#define kIs7 ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)

那么在 iOS 6 及更低版本上不运行仅限 iOS 7 的方法真的很简单:

if (kIs7) [self setNeedsStatusBarAppearanceUpdate];
于 2014-02-04T23:34:45.143 回答
0

这就是您将状态栏颜色更改为白色的方式。如果它不起作用,那么您可能没有在Info.plist.

确保添加以下键,并将其值设置为YES

View controller-based status bar appearance
于 2014-02-04T23:02:00.280 回答