iOS中的表单按钮选项UIActionSheet常用方法整理

2020-01-15 16:21:05王冬梅

什么是操作表单?看图:

iOS,UIActionSheet,选项

一看图就明白了,毋需多说。

复制代码
UIActionSheet* mySheet = [[UIActionSheet alloc] 
                           initWithTitle:@"ActionChoose"  
                           delegate:self  
                           cancelButtonTitle:@"Cancel" 
                           destructiveButtonTitle:@"Destroy" 
                           otherButtonTitles:@"OK", nil]; 
    [mySheet showInView:self.view]; 
与UIAlertView类似,我们也是在委托方法里处理按下按钮后的动作。记得在所委托的类加上UIActionSheetDelegate。
复制代码
- (void)actionSheetCancel:(UIActionSheet *)actionSheet{ 
    // 

- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    // 

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{ 
    // 

-(void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{ 
    // 

看到那个红色的按钮没?那是ActionSheet支持的一种所谓的销毁按钮,对某户的某个动作起到警示作用,
比如永久性删除一条消息或者日志。如果你指定了一个销毁按钮他就会以红色高亮显示:
复制代码
mySheet.destructiveButtonIndex=1; 
与导航栏类似,操作表单也支持三种风格 :
复制代码
UIActionSheetStyleDefault              //默认风格:灰色背景上显示白色文字 
UIActionSheetStyleBlackTranslucent     //透明黑色背景,白色文字 
UIActionSheetStyleBlackOpaque          //纯黑背景,白色文字