UIImagePickerController inside UIPopoverController doesn't show Cancel button on iOS7 - ios

I'm using UIImagePickerController inside a UIPopoverController to select image just from photo albums. When I launch app on device running iOS 8, the Cancel button on the top right of the pop over appeared normally like this:
But when I launch the app on device running iOS 7, the Cancel button disappeared:
The code I used to show the picker:
UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
[pickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
pickerController.delegate = self;
_popOver = [[UIPopoverController alloc] initWithContentViewController:pickerController];
_popOver.delegate = self;
pickerController.navigationBar.tintColor = [UIColor redColor];//Cancel button text color
[pickerController.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName: [UIColor blackColor]}];// title color
if (isImage) {
[pickerController setMediaTypes:#[(NSString*)kUTTypeImage]];
} else
[pickerController setMediaTypes:#[(NSString*)kUTTypeMovie]];
[_popOver presentPopoverFromRect:CGRectMake(1024/2, 768/2, 1, 1) inView:self.view permittedArrowDirections:0 animated:YES];
What can I do to show that Cancel button on iOS7? My app design doesn't allow user to dismiss the popover by tapping anywhere outside the popover view.
Thank you.

#JozoL Write the Below Code this works
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
UINavigationItem *pickerNavBarTopItem;
// add done button to right side of nav bar
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Cancel"
style:UIBarButtonItemStylePlain
target:self
action:#selector(doSomething)];
UINavigationBar *bar = navigationController.navigationBar;
[bar setHidden:NO];
pickerNavBarTopItem = bar.topItem;
pickerNavBarTopItem.rightBarButtonItem = doneButton;
}
-(void)doSomething{
}

For swift2.x you can try below code, Its work for me
pickerController.navigationBar.tintColor = UIColor.blueColor()

In my case, UIImagePickerController was not showing its cancel button
. So I tried adding this line to code:
pickerController.navigationBar.barStyle = UIBarStyleDefault;
And this worked for me.Try setting color of Cancel button like this
pickerController.navigationBar.tintColor = [UIColor blackColor];
Try using this code and let me know if it helps you.

Related

UINavigationBar leftBarButtonItem position

I have an iOS project with UINavigationController.
When I pushviewcontroller with
animated = YES
[self.navigationController pushViewController:viewController animated:YES];
the top leftbarbuttonitem (with image) is well positioned.
But if I set pushviewcontroller with
animated = NO
[self.navigationController pushViewController:viewController animated:NO];
the top leftbarbuttonitem (with image) is not positioned exactly the same place with previous one. Does anyone have any idea?
SAMPLE CODE
- (void)addBackButtonWithoutAnimation {
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
UIImage *closeImage = [UIImage imageNamed:#"icon_back"];
UIBarButtonItem *closeBackButton = [[UIBarButtonItem alloc] initWithImage:closeImage style:UIBarButtonItemStylePlain target:self action:#selector(closeBackButtonwithoutAnimationDidClick)];
self.navigationItem.leftBarButtonItem = closeBackButton;
self.navigationItem.hidesBackButton = YES;}

add a back button to UIImagepicker controller navigation nar

i have a UI Image picker and its being shown inside a UI popoverController, i need a back button on UIimage picker navbar, so i can go back to previous popover.
let me explain in details.
1) i have a popup in which i tap and raise a notification, this notification is read on a view controller where i want this camera image picker popup. following is my code
-(void)registerNotificationForCameraSource
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(mediaSourceCallback:) name:NOTIFICATION_FOR_CAMERA_SOURCE object:nil];
}
#pragma mark - Image picker Popover
-(void)mediaSourceCallback:(NSNotification *)notificationObj
{
capturedImages = [[NSMutableArray alloc] init];
pickerObj = [[UIImagePickerController alloc] init];
// [pickerObj setContentSizeForViewInPopover:CGSizeMake(320,480)];
pickerObj.delegate = self;
if ([notificationObj.object isEqualToString:#"UIImagePickerControllerSourceTypeCamera"])
{
pickerObj.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerObj.modalPresentationStyle = UIModalPresentationFullScreen;
pickerObj.showsCameraControls = YES;
[self presentViewController:pickerObj animated:YES completion:nil];
}
else
{
[[UINavigationBar appearanceWhenContainedIn:[ApplicationDiscriptionPopupViewController class], nil] setBarTintColor:[UIColor redColor]];
pickerObj.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:#"Back" style:UIBarButtonItemStyleDone target:self action:#selector(imagePickerBackButtonTapped)];
[pickerObj.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
[pickerObj setNavigationBarHidden:NO animated:YES];
//navigationControllerObj = [[UINavigationController alloc] initWithRootViewController:applicationDiscriptionPopupViewControllerObj];
_popoverControllerObj.popoverContentSize = CGSizeMake(320,480);
pickerObj.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[pickerObj presentedViewController];
[_popoverControllerObj setContentViewController:pickerObj animated:YES];
}
}
-(void)imagePickerBackButtonTapped
{
[pickerObj popToViewController:applicationDiscriptionPopupViewControllerObj animated:YES]; }
pickerObj is UI Image picker
applicationDiscriptionPopupViewControllerObj is view controller of my previous popover view. from where i came. now i wana go back to this view in the popup, when i tap on back button in nav bar.
but i dnt hav any nav bar. plz help
If you are adding a UIImagePickerController via presentViewController inside a UIViewController then you should see the default navigation bar. You should implement :
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
UINavigationItem *navBarTopItem;
// you cannot add a custom back button with native back button look like, so use image over
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"back_arrow.png"]
style:UIBarButtonItemStyleBordered
target:self
action:#selector(backAction)];
navBarTopItem.title = #"Albums"; // "Camera
navBarTopItem.leftBarButtonItem = backButton;
}
Add a back button action handler
-(void)backAction{
[self.navigationController popViewControllerAnimated:YES];
}
Hope that answer ur Q.

ABUnknownPersonVIewController and NavigationBarColor

I've converted an app from ios6 to ios7. The app sets the background color of the navigationbar in the following way.
[[UINavigationBar appearance] setBackgroundColor: [UIColor blueColor]];
This works fine almost everywhere. But when I use the ABUnknownPersonViewController and click "create new contact" or "add to existing contact" the header is white on white background.
Is there any way to change the navbar background color of this view?
The view is initiated like this
ABUnknownPersonViewController *picker = [[ABUnknownPersonViewController alloc] init];
picker.unknownPersonViewDelegate = self;
picker.displayedPerson = aContact;
picker.allowsAddingToAddressBook = YES;
picker.allowsActions = YES;
picker.alternateName = self.contact.fullName;
picker.title = self.contact.fullName;
[self.navigationController pushViewController:picker animated:YES];
The first view looks fine with the custom header/background color. It's when you click "add" or "create" that the header goes white.
Thanks
Johan
Try
[[UINavigationBar appearance] setBarTintColor: [UIColor blueColor]];
try like this....
ABUnknownPersonViewController *picker = [[ABUnknownPersonViewController alloc] init];
UINavigationController *newNavigationController = [[UINavigationController alloc] initWithRootViewController:picker];
// customise navigation bar of navigation controller
[self presentModalViewController:newNavigationController animated:YES];

iOS 7 backBarButtonItem hidden

I've an issue with back bar button. It stay hidden no matter that i do like self.navigationItem.hidesBackButton
Here is my code to add back button:
//
- (void)viewDidLoad{
[.....];
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"UI_BTN_BACK", nil) style:UIBarButtonItemStylePlain target:nil action:nil];
back.tintColor = [Templates getColor:#"color"];
[[self navigationItem] setBackBarButtonItem:back];
// Parent
[super viewDidLoad];
}
Button stay hidden BUT going back works if if touch on the place where it should be.
Of course it works on iOS6.
Another detail: back button seems to appear when i set UINavigationBar translucent to YES.
Thanks
[self.navigationItem setHidesBackButton:YES];
Check out this.
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
Use this code:
self.navigationItem.backBarButtonItem = nil;
OR
self.navigationItem.leftBarButtonItem = nil;

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