How to create action sheet Delete in IOS [closed]

2019-09-30 08:08发布

问题:

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

回答1:

Simply use that code make make delete button as 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];


回答2:

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


回答3:

Try below code

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


回答4:

There are many ready codes are available on github for this type of action sheet.

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


回答5:

You can download sample project from https://github.com/russj/MBActionSheet/ and can customize your action sheet. You can design your buttons and add to actionsheet using following code

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

and call this method where you are creating action sheet.