I am new to iOS and I am facing a problem regarding UIActionSheet.
My code is like this
-(IBAction)picimgbtnClick:(id)sender
{
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Profile Photo" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:
@"Gallery",
@"Camera",
@"Remove Photo",
nil];
popup.tag = 1;
[popup showInView:self.view];
}
This works perfectly on iPhone but when I run this on an iPad, the UIActionSheet appears in the middle (see image below) and also doesn't show a cancel button:
On iPhone, it appears like this:

At first UIActionSheet is now deprecated so use latest code for it.
- (IBAction)capture:(UIButton *)sender {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"Camera" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// Code for Cam
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Gallery" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Code for Gallery
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Remove Photo" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Code for removing photo
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[alert setModalPresentationStyle:UIModalPresentationPopover];
UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
popPresenter.sourceView = sender;
popPresenter.sourceRect = sender.bounds; // You can set position of popover
[self presentViewController:alert animated:TRUE completion:nil];
}
And as @balkaran singh said it's a default behaviour for ipad . you can not change it. If you want then you concrete your custom class and by animation you can get exact UI what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With