最近在写项目的时候出现了个问题,就是使用UIImagePickerController获取图库照片后,发现statusBar的颜色从白色变成了黑色(我整个项目都是白色)
然后点击头像进入相册选择照片的时候变成这样.
显然是UIImagePickerController的navigationbar在作怪,在调用UIImagePickerController的地方,加上如下代码:
#pragma mark -UINavigationControllerDelegate
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
//跳转到UIImagePickerController的时候使statusBar得颜色还是白色
if ([ navigationController isKindOfClass:[UIImagePickerController class] ]) {
navigationController.navigationBar.barStyle = UIStatusBarStyleLightContent;
}
}
在网上看到只有这种方法:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
// bug fixes: UIIMagePickerController使用中偷换StatusBar颜色的问题
if ([navigationController isKindOfClass:[UIImagePickerController class]] ) {
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication]
setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
}
}