如何在UIImagePicker中更改条形颜色?

时间:2012-07-03 15:06:20

标签: ios uiimagepickercontroller

我正在尝试将相机视图中的条纹着色为黑色。到目前为止,以下方法都没有奏效。我想要更改2个视图,第一个带有摄像头图标和“取消”,第二个带有“重拍”和“使用”按钮。有什么想法吗?

- (void)openCamera {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.navigationBar.barStyle = UIBarStyleBlackOpaque;
    picker.toolbar.barStyle = UIBarStyleBlackOpaque;
    picker.navigationBar.tintColor = [UIColor blackColor];
    [self presentModalViewController:picker animated:NO];
}

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    UIImagePickerController *picker = (UIImagePickerController *)navigationController;
    if((picker)&&(picker.sourceType == UIImagePickerControllerSourceTypeCamera))
    {
        picker.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
        picker.navigationController.toolbar.barStyle = UIBarStyleBlackOpaque;
        picker.navigationBar.tintColor = [UIColor blackColor];
    }
}

2 个答案:

答案 0 :(得分:2)

使用UIAppearance可能会有运气。查看documentation

答案 1 :(得分:0)

您可以使用UIImagePickerController showsCameraControlscameraOverlayViewUIImagePickerController上使用自定义视图。将showsCameraControls值设置为NO将隐藏UIImagePickerController上的所有内容,但会隐藏摄像机视图。 cameraOverlayView允许您将自己的视图放在摄像机视图上。然后,您可以使用自己的底栏,自己的按钮创建视图......并将其放在UIImagePicker的前面。

UIView *overlayView = [[UIView alloc] init];
/* Customize overlayView with your bottomBar and button */
UIImagePickerController imagePickerController = [[UIImagePickerController alloc] init];
/* Configure your UIImagePickerController for picture and/or video */
imagePickerController.showsCameraControls = NO; //Must be set to NO if you want to use the cameraOverlayView
imagePickerController.cameraOverlayView = overlayView;
overlayView = nil;

不幸的是,使用此方法,您必须重新创建原始UIImagePickerController视图的所有按钮(闪光模式按钮,选项按钮,...),如果您想使用它们,则必须创建自己的导航控制器使用“重拍”和“使用”按钮进入视图。但实施起来非常简单。