UIActionSheet
.h 文件
@interface ViewController : UIViewController<UIActionSheetDelegate>
- (IBAction)ShowActionSheet:(id)sender;
.m 文件
- (IBAction)ShowActionSheet:(id)sender{
UIActionSheet *actionSheet=[[UIActionSheet alloc]initWithTitle:@"Hello" delete:self cancelButtonTitle:@"取消" desturctiveButtonTitle:@"第一项" otherButtonTitles:@"第二项",@"第三项",nil];
actionSheet.actionSheetStyle=UIActionSheetStyleAutomatic; //灰色背景 和 Default一样
*UIActionSheetStyleBlackTranslucent //黑色半透明背景
*UIActionSheetStyleBlackOpaque //纯黑色背景
*UIActionSheetStyleBlackDefault //灰色背景
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex=X){do...}
}
UIAlertView
.h 文件
@Interface ViewController:UIViewController<UIAlertViewDelegate>
.m 文件
- (void)ShowAlertView{
UIAlertView *alert=[UIAlertView alloc]initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles@"One",@"Two",nil);
[alert Show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"buttonIndex:%d",buttonIndex);
}