问题
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?
回答1:
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.
回答2:
I will give the best method to achieve this:
- First create a subclass of the UiImagePickerController
- in the subclass respond to the
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.
- in this method return
NO
for the cancel item (which is the first one)
回答3:
I did this with ELCImagePickerController
回答4:
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];
回答5:
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
回答6:
Swift Version, compatible 4+
To remove the navigation bar :
imagePicker.view.subviews
.filter { $0.isKind(of: UINavigationBar) }
.map { $0.isHidden = true }
for removing the buttons only :
imagePicker.view.subviews
.filter { $0.isKind(of: UIButton) }
.map { $0.isHidden = true }
Voilà
回答7:
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
来源:https://stackoverflow.com/questions/8708219/removing-cancel-button-in-uiimagepickercontroller