Xummer

UIImagePickerController iOS7 状态栏颜色

需要自定义推出的UIImagePickerController的导航栏,但是推出的后的StatusBar一直是深色的。

默认风格

自定义后出现的效果

最终需要的效果

iOS7 的 SDK 中 UIViewController多了2个控制 StatusBar 的方法,

- (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0); // Defaults to UIStatusBarStyleDefault

- (BOOL)prefersStatusBarHidden NS_AVAILABLE_IOS(7_0); // Defaults to NO

但是UIImagePickerController我们无法在里面改写方法, 首先找到方法,推出UIImagePickerController之前,设置全局的statusBarStyle.

设置全局的statusBarStyle 无效)

实测 iOS 7.1 无效

#pragma mark - UINavigationControllerDelegate

- (void)navigationController:(UINavigationController *)navigationController
      willShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated {

    if ([navigationController isKindOfClass:[UIImagePickerController class]] &&
        ((UIImagePickerController *)navigationController).sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum) {
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
    }
}

解决方法 子类化UIImagePickerController

@interface CustomImagePickerController : UIImagePickerController
@end

@implementation CustomImagePickerController
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent; // change this to match your style
}
@end

NavigationBar

UIImagePickerControllerNavigationBar 默认带了毛玻璃效果,若要取消

picker.navigationBar.translucent = NO;

-以上-