UIActionSheet的集成关系:
UIActionSheet:UIView:UIResponder:NSObject
- (void)viewDidLoad
{
[super viewDidLoad];
/**
1、初始化
- initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:
*/
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"分享测试"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"完成"
otherButtonTitles:@"微博",@"微信", nil];
/**
2、设置属性
.title //设置标题
.visible //获取是否显示,判断控件是否显示 (只读属性)
.actionSheetStyle //设置类型
*/
actionSheet.title = @"分享测试一下";
/**
3、配置按钮
- addButtonWithTitle: //添加新的按钮
.numberOfButtons //总的按钮数
.cancelButtonIndex //取消按钮的index
.destructiveButtonIndex //特殊标记按钮的index 注意:如果销毁按钮不为nil,则index==0;否则为-1。
.firstOtherButtonIndex //第一个其他按钮的index 注意:如果销毁按钮为nil,则第一个其他按钮的index==1;否则为0。
- buttonTitleAtIndex: //根据索引,获取按钮的标题
*/
[actionSheet addButtonWithTitle:@"QQ"];
NSLog(@"numberOfButtons:%ld", (long)actionSheet.numberOfButtons);
NSLog(@"cancelButtonIndex:%ld", (long)actionSheet.cancelButtonIndex);
NSLog(@"destructiveButtonIndex:%ld",(long)actionSheet.destructiveButtonIndex);
NSLog(@"firstOtherButtonIndex:%ld", (long)actionSheet.firstOtherButtonIndex);
NSLog(@"buttonTitleAtIndex2:%@",[actionSheet buttonTitleAtIndex:2]);
/**
4、几种弹出方式,会根据风格不同展现不同的方式
- showFromTabBar:
- showFromToolbar:
- showInView:
- showFromBarButtonItem:animated:
- showFromRect:inView:animated:
*/
[actionSheet showInView:self.view];
/**
5、回收ActionSheet
- dismissWithClickedButtonIndex:animated:
*/
/**
6、代理
.delegate //设置代理
- actionSheet:clickedButtonAtIndex: //点击按钮时触发的方法
- willPresentActionSheet: //视图将要弹出时触发的方法
- didPresentActionSheet: //视图已经弹出式触发的方法
- actionSheet:willDismissWithButtonIndex: //点击按钮后,视图将要收回时触发的方法
- actionSheet:didDismissWithButtonIndex: //点击按钮后,视图已经收回时触发的方法
- actionSheetCancel:
*/
}