【问题标题】:how to change color of status bar of imagepickercontroller ios?如何更改 imagepickercontroller ios 状态栏的颜色?
【发布时间】:2017-03-23 10:48:11
【问题描述】:
我需要像 status bar image 这样的东西,但我的状态是隐藏的,但我仍然无法更改颜色。我收到了这个status bar withour color
这就是我正在做的。
-
(void)showGallery
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.allowsEditing = NO;
// picker.navigationBarHidden = YES;
// picker.toolbarHidden = YES;
picker.navigationController.navigationBar.barTintColor=[UIColor orangeColor];
picker.navigationBar.backgroundColor = [UIColor orangeColor];
picker.navigationBar.barStyle=UIBarStyleBlack;
[ picker.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
[self presentViewController:picker animated:YES completion:NULL];
}
【问题讨论】:
标签:
ios
iphone
ios7
uiimagepickercontroller
ios7-statusbar
【解决方案1】:
Try This:-
1.创建一个高度为 20 点的视图并更改背景颜色以附加视图控制器视图(或)更改视图控制器的背景颜色,如下所示
UIView*statusbarview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
statusbarview.backgroundColor = [UIColor greenColor];
[self.view addSubview:statusbarview];
(或)
self.view.backgroundColor = [UIColor redColor];
【解决方案2】:
This solved my problem.
-(void)showGallery
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.allowsEditing = NO;
picker.modalPresentationStyle = UIModalPresentationFullScreen;
picker.navigationBar.translucent = NO;
picker.navigationBar.barTintColor = [UIColor orangeColor];
picker.navigationBar.tintColor = [UIColor whiteColor];
picker.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
[self presentViewController:picker animated:YES completion:nil];
}
【解决方案3】:
使用三个步骤:
1:将UINavigationControllerDelegate、UIImagePickerControllerDelegate 添加到您的@interface yourController ()<>
2:
imagePickerController.delegate = self;
3:
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}