Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In UIImagePickerController Cancel button not showing?

here i m using below code. please help me if anybody know this issue. and i tried below urls also, but its not working. please help me

iOS7 UIImagePickerController cancel button disappear UIImagePickerController inside UIPopoverController doesn't show Cancel button on iOS7

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
picker.navigationBar.tintColor = [UIColor redColor];
picker.navigationBar.barStyle = UIBarStyleBlackOpaque;
picker.navigationBar.topItem.rightBarButtonItem.tintColor = [UIColor blackColor];

My Issue: enter image description here

My Req: enter image description here

like image 834
Venkatesh G Avatar asked Feb 10 '15 10:02

Venkatesh G


3 Answers

Subclass UIPickerViewController as below:

class CustomImagePicker: UIImagePickerController {

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        UINavigationBar.appearance().tintColor = UIColor.black
        UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.init(red: 0.0, green: 122.0/255.0, blue: 1.0, alpha: 1.0)], for: .normal)
    }

    override func viewWillDisappear(_ animated: Bool) {

        UINavigationBar.appearance().tintColor = UIColor.white // your color
        UIBarButtonItem.appearance().setTitleTextAttributes(nil, for: .normal)
        super.viewWillDisappear(animated)

    }

}

And use As:

func openGallary()
    {
        picker!.sourceType = UIImagePickerController.SourceType.photoLibrary
        picker!.modalPresentationStyle = .currentContext
        self.present(picker!, animated: true, completion: nil)
    }
like image 116
Avijit Nagare Avatar answered Oct 05 '22 23:10

Avijit Nagare


This is what worked for me:

    present(imagePicker, animated: true, completion: {
        imagePicker.navigationBar.topItem?.rightBarButtonItem?.tintColor = .black
    })
like image 8
Lucas Avatar answered Nov 10 '22 15:11

Lucas


Looks like apple made some mistake with it (iOS 10, Xcode 8) because just changing tint color of UIImagePickerController could not be done, cause, before controller isn't have topItem property, or navigationController property. So have done the changes in UIImagePickerController extension. But I checked navigationController and topItem in those overrided methods: viewDidLoad, viewWillAppear, viewDidAppear. but it still was nil. So i decide to check it in viewWillLayoutSubviews, and voila! It's wasn't nil, so we can set bar tint color of exact rightBarButtomItem here!

Here is example:

    extension UIImagePickerController {
        open override func viewWillLayoutSubviews() {
            super.viewWillLayoutSubviews()
            self.navigationBar.topItem?.rightBarButtonItem?.tintColor = UIColor.black 
            self.navigationBar.topItem?.rightBarButtonItem?.isEnabled = true
        }
    }

Exampel on simulator (but it tested on )

And don't forget to call super.viewWillLayoutSubviews, it's very important ;-) EDIT: But it still has problems when return to the albums screen..

like image 3
KostiaZzz Avatar answered Nov 10 '22 15:11

KostiaZzz