步骤:1.
//创建一个UIActionSheet对象,初始化
//initWithTitle:sheet的标题
//delegate:sheet的代理
//cancelButtonTitle:sheet的取消按钮
//destructiveButtonTitle:sheet的确定按钮
//otherButtonTitles:sheet的其他选项
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"提示"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:@"第一项"otherButtonTitles:@"第二项",@"第三项",@"第四项",nil];
//为sheet添加样式
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
//指定sheet在哪个视图上面显示
//initWithTitle:sheet的标题
//delegate:sheet的代理
//cancelButtonTitle:sheet的取消按钮
//destructiveButtonTitle:sheet的确定按钮
//otherButtonTitles:sheet的其他选项
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"提示"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:@"第一项"otherButtonTitles:@"第二项",@"第三项",@"第四项",nil];
//为sheet添加样式
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
//指定sheet在哪个视图上面显示
[actionSheet showInView:self.view];
2.
//sheet的代理方法,根据buttonIndex来实现对应的方法
//第一项,第二项,第三项,取消 分别代表:buttonIndex == 0, 1, 2, 3
- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
self.view.backgroundColor= [UIColororangeColor];
}
if (buttonIndex == 1) {
self.view.backgroundColor= [UIColorblackColor];
}
if (buttonIndex == 2) {
self.view.backgroundColor= [UIColorblueColor];
}
if (buttonIndex == 3) {
self.view.backgroundColor= [UIColorgreenColor];
}
if (buttonIndex == 4) {
self.button.backgroundColor= [UIColorblackColor];
}
//第一项,第二项,第三项,取消 分别代表:buttonIndex == 0, 1, 2, 3
- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
self.view.backgroundColor= [UIColororangeColor];
}
if (buttonIndex == 1) {
self.view.backgroundColor= [UIColorblackColor];
}
if (buttonIndex == 2) {
self.view.backgroundColor= [UIColorblueColor];
}
if (buttonIndex == 3) {
self.view.backgroundColor= [UIColorgreenColor];
}
if (buttonIndex == 4) {
self.button.backgroundColor= [UIColorblackColor];
}
}