状态栏的字体为黑色:UIStatusBarStyleDefault状态栏的字体为白色:UIStatusBarStyleLightContent一、在info.plist中,将View controller-based status bar appearance设为NO状态栏字体的颜色只由下面的属性设定,默认为白色:// default is UIStatusBarStyleDefault[UIapplication sharedApplication].statusBarStyle解决个别vc中状态栏字体颜色不同的办法1、在info.plist中,将View controller-based status bar appearance设为NO.2、在app delegate中:[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;3、在个别状态栏字体颜色不一样的vc中-(void)viewWillAppear:(BOOL)animated{[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;}-(void)viewWillDisappear:(BOOL)animated{[super viewWillDisappear:animated];[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;}二、在info.plist中,将View controller-based status bar appearance设为YES,或者没有设置。View controller-based status bar appearance的默认值就是YES。如果View controller-based status bar appearance为YES。则[UIApplication sharedApplication].statusBarStyle 无效。用下面的方法:1、在vc中重写vc的PReferredStatusBarStyle方法。-(UIStatusBarStyle)preferredStatusBarStyle{return UIStatusBarStyleDefault;}2、在viewDidload中调用:[self setNeedsStatusBarAppearanceUpdate];但是,当vc在nav中时,上面方法没用,vc中的preferredStatusBarStyle方法根本不用被调用。原因是,[self setNeedsStatusBarAppearanceUpdate]发出后,只会调用navigation controller中的preferredStatusBarStyle方法,vc中的preferredStatusBarStyley方法跟本不会被调用。解决办法有两个:方法一:设置navbar的barStyle 属性会影响status bar 的字体和背景色。如下。//status bar的字体为白色//导航栏的背景色是黑色。self.navigationController.navigationBar.barStyle = UIBarStyleBlack;//status bar的字体为黑色//导航栏的背景色是白色,状态栏的背景色也是白色。//self.navigationController.navigationBar.barStyle = UIBarStyleDefault;方法二:自定义一个nav bar的子类,在这个子类中重写preferredStatusBarStyle方法:MyNav* nav = [[MyNav alloc] initWithRootViewController:vc];self.window.rootViewController = nav;@implementation MyNav- (UIStatusBarStyle)preferredStatusBarStyle{UIViewController* topVC = self.topViewController;return [topVC preferredStatusBarStyle];}
新闻热点
疑难解答