我想创建与删除按钮红色和取消按钮相同的动作表。我怎样才能做到这一点?非常感谢
答案 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上有许多准备好的代码可用于此类操作表。
答案 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];
}
并在创建操作表的地方调用此方法。