从UIActionSheet弹出窗口中去除填充

3

我正在创建一个UIActionSheet,允许用户拍摄或选择照片。有人能告诉我为什么它不能像苹果的一样显示吗?这是为iPad设计的,所以我没有声明取消按钮。

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];

苹果的通讯录应用。边距很小,行之间有线条。
这是我的工作示例应用。底部有额外的填充,行之间没有线条。
感谢您提供的任何见解。
3个回答

3

试试这个

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

你仍然需要声明一个取消按钮。当在iPad上运行时,它将简单地忽略取消按钮,而在iPhone上,则会使用它。


糟糕!这似乎解释了它。谢谢。 - DenVog

0

我想保持使用 addButtonWithTitle 的灵活性,但不幸的是,在 iPad 上,它不会在底部按钮上方显示一条线。这个方法很有效。如果有取消按钮,iPad 会自动切掉最后一个按钮。如果你在 iPad 上,就不需要取消按钮。

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];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接