Remove Padding from UIActionSheet Popover

送分小仙女□ 提交于 2019-12-10 19:47:17

问题


I am creating a UIActionSheet to allow users to Take or Select a photo. Can someone tell me why it does not display the same as Apple's? This is for the iPad, so I have not declared a Cancel button.

UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
actionSheet.delegate = self;
[actionSheet addButtonWithTitle:NSLocalizedString(@"choosePhotoPopoverButton", @"Choose Photo - Get a photo from the album.")];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
    [actionSheet addButtonWithTitle:NSLocalizedString(@"takePhotoPopoverButton", @"Take Photo - Use camera to take photo.")];
}
[actionSheet showFromRect:self.imageView.frame inView:self animated:YES];

Apple's Contacts app. Tight margins. Line between rows.

My working app example. Extra padding at bottom. No line between rows.

Thanks for any insight.


回答1:


Try this

UIActionSheet *actionSheet;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
    actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate: self cancelButtonTitle:@"" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo",@"Camera", nil];
}else{
    actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate: self cancelButtonTitle:@"" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo", nil];
}

[actionSheet showFromRect:self.imageView.frame inView:self animated:YES];



回答2:


You still need to declare a cancel button. When running on the iPad it will simply ignore the cancel button, whereas on iPhone it will use it




回答3:


I wanted to maintain the flexibility of using addButtonWithTitle, but unfortunately on the iPad, it doesn't show a line above the bottom button. This did the trick. The iPad automatically chops off the last button if there's a cancel button. If you're on the iPad, you don't need a Cancel button.

UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
actionSheet.delegate = self;
[actionSheet addButtonWithTitle:NSLocalizedString(@"choosePhotoPopoverButton", @"Choose Photo - Get a photo from the album.")];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
    [actionSheet addButtonWithTitle:NSLocalizedString(@"takePhotoPopoverButton", @"Take Photo - Use camera to take photo.")];
}
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:(@"Cancel");
[actionSheet showFromRect:self.imageView.frame inView:self animated:YES];


来源:https://stackoverflow.com/questions/20907395/remove-padding-from-uiactionsheet-popover

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!