标签:
UIAlertView和UIActionSheet相似,区别很小, 很容易理解。
// // ViewController.m // UIActionSheet // // Created by City--Online on 15/5/18. // Copyright (c) 2015年 XQB. All rights reserved. // #import "ViewController.h" @interface ViewController ()<UIActionSheetDelegate> @property(nonatomic,strong) UIActionSheet *actionSheet; @property(nonatomic,strong) UIActionSheet *actionSheet1; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //设置Frame无效 _actionSheet=[[UIActionSheet alloc]initWithFrame:CGRectMake(20, 20, 200, 100)]; [_actionSheet addButtonWithTitle:@"相册"]; [_actionSheet addButtonWithTitle:@"相机"]; [_actionSheet addButtonWithTitle:@"取消"]; _actionSheet.cancelButtonIndex=2; _actionSheet.destructiveButtonIndex=1; _actionSheet.title=@"提示"; _actionSheet.delegate=self; // typedef NS_ENUM(NSInteger, UIActionSheetStyle) { // UIActionSheetStyleAutomatic = -1, // take appearance from toolbar style otherwise uses ‘default‘ // UIActionSheetStyleDefault = UIBarStyleDefault, // UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent, // UIActionSheetStyleBlackOpaque = UIBarStyleBlackOpaque, // }; _actionSheet.actionSheetStyle=UIActionSheetStyleBlackOpaque; _actionSheet.tag=10001; NSLog(@"firstOtherButtonIndex=%ld",_actionSheet.firstOtherButtonIndex); for (int i=0; i<_actionSheet.numberOfButtons; i++) { NSLog(@"i=%d %@",i,[_actionSheet buttonTitleAtIndex:i]); } [_actionSheet showInView:self.view]; _actionSheet1 =[[UIActionSheet alloc]initWithTitle:@"提示" delegate:self cancelButtonTitle:@"NO" destructiveButtonTitle:@"DestructiveButton" otherButtonTitles:@"YES", nil]; _actionSheet1.tag=10002; for (int i=0; i<_actionSheet1.numberOfButtons; i++) { NSLog(@"i=%d %@",i,[_actionSheet1 buttonTitleAtIndex:i]); } [_actionSheet1 showInView:self.view]; } //UIActionSheetDelegate - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (actionSheet.tag==10001) { NSString *title=[_actionSheet buttonTitleAtIndex:buttonIndex]; NSLog(@"我点击了: %@",title); } else { if (buttonIndex==2) { [_actionSheet dismissWithClickedButtonIndex:2 animated:YES]; } } } //以下这些和UIAlertView的相似 - (void)actionSheetCancel:(UIActionSheet *)actionSheet { NSLog(@"actionSheetCancel"); } - (void)willPresentActionSheet:(UIActionSheet *)actionSheet { NSLog(@"willPresentActionSheet"); } - (void)didPresentActionSheet:(UIActionSheet *)actionSheet { NSLog(@"didPresentActionSheet"); } - (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex { NSLog(@"willDismissWithButtonIndex"); } - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { NSLog(@"didDismissWithButtonIndex"); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
标签:
原文地址:http://www.cnblogs.com/cuiyw/p/4512237.html