如何在IOS中创建操作表删除

时间:2013-07-17 06:23:54

标签: iphone ios objective-c uibutton uiactionsheet

我想创建与删除按钮红色和取消按钮相同的动作表。我怎样才能做到这一点?非常感谢

I want to create action sheet same bellow picture with Delete button red color and Cancel button. How can i do that? Thanks much

5 个答案:

答案 0 :(得分:4)

只需使用该代码,将make delete按钮设为destructiveButton

即可
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure you want to delete this backup?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete Backup" otherButtonTitles:nil,nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:self.view];

答案 1 :(得分:0)

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure you want to delete this backup ?" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete backup" otherButtonTitles:nil, nil];
    [actionSheet showInView:self.view];

答案 2 :(得分:0)

尝试以下代码

  UIActionSheet *objActionSheet = [[UIActionSheet alloc]
                         initWithTitle:@"XYZ Message"
                         delegate:self
                         cancelButtonTitle:@"Cancel"
                         destructiveButtonTitle:@"Delete Backup"
                         otherButtonTitles:nil];

答案 3 :(得分:0)

github上有许多准备好的代码可用于此类操作表。

  1. RDActionSheet for iOS
  2. action-sheet-blocks for iOS
  3. LBActionSheet for iOS
  4. SHActionSheetBlocks for iOS

答案 4 :(得分:0)

您可以从https://github.com/russj/MBActionSheet/下载示例项目,并可以自定义您的操作表。您可以使用以下代码设计按钮并添加到操作表

- (void)createButton:(CGRect)frm buttonTitile:(NSString *)title buttonIndex:(NSInteger)index
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.frame = frm;
    if(index==0){
            [btn setBackgroundImage:[UIImage imageNamed:@"delete.png"] forState:UIControlStateNormal];
    }
    else if(index==1){
            [btn setBackgroundImage:[UIImage imageNamed:@"cancel.png"] forState:UIControlStateNormal];
    }

    [btn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [btn setTag:index];
    [sheetView addSubview:btn];
}

并在创建操作表的地方调用此方法。