Reputation: 361
I am developing an app for ios 5. I need to remove the cancel button on UIImagePickerController i searched for this problem on the forum but didnt get exact answer can someone please help me with this?
Upvotes: 0
Views: 7780
Reputation: 2414
Swift Version, compatible 4+
To remove the navigation bar :
imagePicker.view.subviews
.filter { $0.isKind(of: UINavigationBar) }
.forEach { $0.isHidden = true }
for removing the buttons only :
imagePicker.view.subviews
.filter { $0.isKind(of: UIButton) }
.forEach { $0.isHidden = true }
Voilà
Upvotes: 2
Reputation: 2176
This will hide Navigationbar itself along with the Cancel
and Title
let videoPicker = UIImagePickerController()
for view in videoPicker.view.subviews {
if let navBar = view as? UINavigationBar {
navBar.isHidden = true
}
}
If you want to remove the cancel button alone, dig deep into navBar
Upvotes: 0
Reputation: 4919
I will give the best method to achieve this:
UINavigationBarDelegate
method - (BOOL)navigationBar:(UINavigationBar *)navigationBar
shouldPushItem:(UINavigationItem *)item
you dont have to do anything like setting the delegate or adding a protocol, just override the method inside your custom UIImagePcikerController.
NO
for the cancel item (which is the first one)Upvotes: 1
Reputation: 799
There isn't a way to remove only the cancel button. UIImagePickerController exposes a property called showCameraControls, which will hide the bottom bar with the cancel button and the camera button, as well as the controls for flash, HDR, and flip camera, giving you just the camera preview.
If you want to provide an experience without a cancel button, you'll have to create a camera overlay view of what you want.
Assuming you have code invoking UIImagePickerController, you can turn off camera controls like this:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setShowsCameraControls:NO];
Assuming you'll overlay it with your own view without the cancel button, you'll add this (assuming you have a UIView called cameraOverlay:
[imagePicker setCameraOverlayView:cameraOverlay];
Upvotes: 0
Reputation: 9740
When you present the UIImagePickerView try puting the below code
for (UIView *subview in view.subviews) {
NSLog(@"subviews=%@",subview);
NSString *className = [NSString stringWithFormat:@"%@", [subview class]];
}
By the above code you can get the navigation controller used for displaying the cancel button.. Once you get the navigationController Set its leftside button to nil..
I have not used it but hope it can be of help to you
Upvotes: -1
Reputation: 2649
That is because it is not possible to remove that cancel button. That is an inbuilt function and you can not make changes in the same.
Upvotes: 2