如何在IOS中创build操作表删除
我想创build与删除button红色和取消button的动作表相同的波纹pipe图片。 我怎样才能做到这一点? 非常感谢
只需使用该代码使make deletebutton成为破坏性的button即可
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];
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];
尝试下面的代码
UIActionSheet *objActionSheet = [[UIActionSheet alloc] initWithTitle:@"XYZ Message" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete Backup" otherButtonTitles:nil];
github上提供了许多现成的代码用于这种types的操作表。
- 适用于iOS的RDActionSheet
- iOS的action-sheet-blocks
- 适用于iOS的LBActionSheet
- 适用于iOS的SHActionSheetBlocks
您可以从https://github.com/russj/MBActionSheet/下载示例项目,并可以自定义您的操作表。 您可以使用以下代码devisebutton并添加到操作表
- (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]; }
并在创build操作表的地方调用此方法。