在底部的UIActionSheet中放置取消按钮

时间:2013-04-22 06:33:34

标签: ios cocoa-touch uiactionsheet

在UIActionSheet中,我有一个uitableview和取消按钮。默认情况下,取消按钮显示在顶部。我想让它在tableview后显示在底部。我该怎么做?

3 个答案:

答案 0 :(得分:6)

这对我有用:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"SomeTitle" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil];
[actionSheet addButtonWithTitle:@"Some Action"];        
[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons -1;

答案 1 :(得分:0)

我试过这个,取消按钮位于底部:

menu = [[UIActionSheet alloc] initWithTitle:@"Actionsheet"
                                                  delegate:self
                                         cancelButtonTitle:@"Cancel"
                                    destructiveButtonTitle:@"destructive"
                                         otherButtonTitles:@"other1", nil];
menu.actionSheetStyle = UIActionSheetStyleDefault;
[menu addButtonWithTitle:@"Cancel"];

默认情况下取消button is hidden,添加取消会显示它。

但是如果你的动作表上还有其他gui元素,你必须

option1)定位那些隐藏其他按钮(为你的gui元素留出空间)。它是一个调整,但可以在某些情况下工作或

option2)您必须手动将按钮添加到操作表

Actionsheet的内置按钮无法自由对齐底部,因为此内置gui元素的用途不同。

请参阅:Adding UIPickerView to UIActionSheet (buttons at the bottom)

答案 2 :(得分:0)

Swift 中的示例:

func presentMyActionSheetIOS7() {
    let actionSheet: UIActionSheet = UIActionSheet(title: "What do you want to do?", delegate: self, cancelButtonTitle: nil, destructiveButtonTitle: nil)

    actionSheet.addButtonWithTitle("Change Transparency")
    actionSheet.addButtonWithTitle("Hide Photo")
    actionSheet.addButtonWithTitle("Cancel")
    actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1

    actionSheet.showInView(self.view)
}

func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) {
    switch buttonIndex {
        case 0:
            println("Change Transparency")
        case 1:
            println("Hide Photo")
        case 2:
            println("Cancel")
        default:
            println("Default")
    }
}