How to create action sheet Delete in IOS [closed]

假装没事ソ 提交于 2019-12-14 03:33:21

问题


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.



来源:https://stackoverflow.com/questions/17692573/how-to-create-action-sheet-delete-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!