How to add the UIImagePickerController in the custom view? - ios

How to add the UIImagePickerController in the view ? If I add the image picker to the view, its show on the full screen. I need to show the on the centre of the view, But UIImagePickerController hide the navigation bar.
How add the UIImagePickerController in the view and also show the navigation bar ?
I am using the following code, I got the output like this(screenshot).
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
imagePicker.showsCameraControls = NO;
imagePicker.navigationBarHidden = NO;
imagePicker.toolbarHidden = YES;
imagePicker.wantsFullScreenLayout = NO;
imagePicker.delegate = self;
imagePicker.cameraOverlayView = cameraOverlayView;
[self presentViewController:imagePicker animated:NO completion:nil];
I need some for show the navigation bar while add the UIImagePickerController in the view. Thanks in advance.

If you are develop application for iPad then you can use popoverviewcontroller to show imagepickerviewcontroller with navigation bar
please see thie link :
How to use UIImagePickerController in iPad?

Correct way to customize media capture here using Assets Library.
Simple way (in some cases) is using overlay view with frame size of whole screen and add controls on that view which simulate navigation bar.
if (_pickerOverlay == nil) {
_pickerOverlay = [[UIView alloc] initWithFrame:self.view.bounds];
//red transparent tint for demo
_pickerOverlay.backgroundColor = [UIColor colorWithRed:1.0
green:0.0
blue:0.0 alpha:0.6];
UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeSystem];
btnBack.frame = CGRectMake(20, 20, 250, 40);
[btnBack setTitle:#"Custom buttom" forState:UIControlStateNormal];
btnBack.backgroundColor = [UIColor whiteColor];
[_pickerOverlay addSubview:btnBack];
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.cameraOverlayView = _pickerOverlay;
[self presentViewController:picker animated:YES completion:nil];

Related

how to change color of status bar of imagepickercontroller ios?

I need something like this status bar image but i am getting the status hidden but still i can not change the color. I am getting this status bar withour color
This is what i am doing.
-
(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];
}
Use three steps:
1: Add UINavigationControllerDelegate, UIImagePickerControllerDelegate to your #interface yourController ()<>
2:
imagePickerController.delegate = self;
3:
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
Try This:-
1.Create a view with height 20 points and change the background color to attach the viewcontrollerView (OR) change the background colour of your view controller follow like
UIView*statusbarview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
statusbarview.backgroundColor = [UIColor greenColor];
[self.view addSubview:statusbarview];
(OR)
self.view.backgroundColor = [UIColor redColor];
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];
}

How to create GalleryShortcut when presenting UIImagePickerController

I want to give option for user to take a photo or upload one as his avatar in my app.
I believe there is no need to put two different buttons for that, so instead I would like to make the next scenario:
user clicks on "Add Picture" button and automatically UIImagePicker with source control - camera is presented.
But, I want to have shortcut for gallery in the corner, where user could click, get into gallery and search for pic he would use.
Here is the screenshot of what I need:
Part with red circle is important part.
How do I put it there?
(Initially it's not there)
There is no pre-build way to do this.
What you can do is to make an overlay for Camera View.
Bear in mind that you have to make different view for each device, as every device already has different positioning inside the CameraView.
One example would be this:
- (IBAction)addImage:(UIButton *)sender {
UIView* overlay = [[UIView alloc] initWithFrame:CGRectMake(20,self.view.frame.size.height-60 , 40, 40)];
overlay.opaque=NO;
overlay.backgroundColor = [UIColor clearColor];
UIButton* btnGallery = [[UIButton alloc]initWithFrame:CGRectMake(0,0 , 40, 40)];
[btnGallery setImage:[UIImage imageNamed:#"image_gallery"] forState:UIControlStateNormal];
btnGallery.backgroundColor = [UIColor whiteColor];
[overlay addSubview:btnGallery];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = YES;
[imagePicker.view addSubview:overlay];
[btnGallery addTarget:self
action:#selector(openGallery)
forControlEvents:UIControlEventTouchUpInside];
_picker = imagePicker;
[self presentViewController:imagePicker
animated:YES
completion:nil];
}
-(void)openGallery
{
UIImagePickerController *gallery = [[UIImagePickerController alloc] init];
gallery.delegate = self;
gallery.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
gallery.mediaTypes = #[(NSString *) kUTTypeImage];
gallery.allowsEditing = YES;
_gallery = gallery;
[_picker presentViewController:gallery
animated:YES
completion:nil];
}

How to set frame in center xcode

Im making iPhone app using frame, my frame is not in center and it repeats. I want to set in center and I hate when my frames repeats multiple times.
Im using following code:
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
// picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
// creating overlayView
UIView* overlayView = [[UIView alloc] initWithFrame:picker.view.frame];
// letting png transparency be
overlayView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"f2.png"]];
[overlayView.layer setOpaque:NO];
overlayView.opaque = NO;
picker.showsCameraControls = NO;
picker.cameraOverlayView = overlayView;
//[self presentModalViewController:picker animated:YES];
[self presentViewController:picker animated:YES completion:nil];
Am I missing something ?
TNX in advance.
I'm not sure, what you are asking, but maybe changing from frame to bounds could solve you problem:
UIView* overlayView = [[UIView alloc] initWithFrame:picker.view.bounds];

UIImagePickerController dismissing when it shouldn't

I am trying to create a custom camera overlay, but am having some problems. The capture view works great, but I would like to show another view where the user can edit the photo after the image is captured. The problem is that when a photo is taken, the view with the photo is automatically dismissed. How would I fix this so that I can show another view controller after the user takes a photo.
Here is how I create the picker:
self.cameraPicker = [[UIImagePickerController alloc] init];
self.cameraPicker.delegate = self;
self.cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.cameraPicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.cameraPicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.cameraPicker.showsCameraControls = NO;
self.cameraPicker.allowsEditing = YES;
self.cameraPicker.navigationBarHidden = YES;
self.cameraPicker.toolbarHidden = YES;
self.cameraPicker.videoQuality = UIImagePickerControllerQualityTypeIFrame1280x720;
self.frontFacing = NO;
self.gridShowing = NO;
self.showingFlash = NO;
// Insert the overlay
CameraOverlayView *overlay = [[CameraOverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
self.cameraPicker.cameraOverlayView = overlay;
overlay.delegate = self;
[self.navigationController presentViewController:(UIViewController *)self.cameraPicker animated:YES completion:nil];
Here is how I take the photo, after this is called, the viewController is dismissed:
, which I do not want:
[self.cameraPicker takePicture];

How to change the bar color in UIImagePicker?

I am trying to color the bars in the camera view black. None of the below approaches worked so far. There are 2 views that I want to change, the first with the camera icon and "cancel", the second with the "retake" and "use" buttons. Any ideas?
- (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];
}
}
You might have some luck using UIAppearance. Look up the documentation.
You can use the UIImagePickerController showsCameraControls and cameraOverlayView to use a custom view over the UIImagePickerController. Setting the showsCameraControlsvalue to NO will hide everything on the UIImagePickerController but the camera view. cameraOverlayView allow you to put your own view over the camera view. You can then create a view with your own bottom bar, your own buttons, ... and put it in front of the 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;
Unfortunately, with this method you must recreate all the buttons of the original UIImagePickerController view (the flash mode button, the options button, ...) if you want to use them, and you have to create your own navigation controller to go to the view with the "retake" and "use" buttons. However it's very simple to implement.

Resources