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.
- RDActionSheet for iOS
- action-sheet-blocks for iOS
- LBActionSheet for iOS
- 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.