问题
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