簡體   English   中英

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

[英]Place Cancel button in UIActionSheet at the bottom

在UIActionSheet中,我有一個uitableview和取消按鈕。 默認情況下,取消按鈕顯示在頂部。 我想讓它在tableview后顯示在底部。 我怎么做?

這對我有用:

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;

我試過這個,取消按鈕在底部:

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

默認情況下,取消按鈕被隱藏 ,添加取消將顯示它。

但是:如果你必須在你的動作表上有其他的gui元素

option1)定位那些隱藏其他按鈕(為你的gui元素留出空間)。 它是一個調整,但可以在某些情況下工作或

option2)您必須手動將按鈕添加到操作表

Actionsheet的內置按鈕無法自由對齊底部,因為此內置gui元素的用途不同。

請參閱: 將UIPickerView添加到UIActionSheet(底部的按鈕)

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")
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM