欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-12-14 17:13:04
什么是操作表单?看图: 一看图就明白了,毋需多说。 复制代码 代码如下: uiactionsheet* mysheet = [[uiactionsheet a...

什么是操作表单?看图:

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          //纯黑背景,白色文字 

用法用例:
复制代码 代码如下:

mysheet.actionsheetstyle = uiactionsheetstyleblackopaque;

常用方法和属性

显示actionsheet方法:
1.在一个视图内部显示,可以用showinview

复制代码 代码如下:

[mysheet showinview:self];

2.如果要将actonsheet 与工具栏或者标签栏对齐,可以使用showfromtoolbar或showfromtabbar
复制代码 代码如下:

[mysheet showfromtoolbar:toolbar];
[mysheet showfromtabbar:tabbar];

解除操作表单
用户按下按钮之后,actionsheet就会消失——除非应用程序有特殊原因,需要用户按下做个按钮。用dismiss方法可令表单消失:

复制代码 代码如下:

[mysheet dismisswithclickbuttonindex:1 animated:yes]; 
@property(nonatomic,copy) nsstring *title;

设置标题

复制代码 代码如下:

@property(nonatomic) uiactionsheetstyle actionsheetstyle;

添加一个按钮,会返回按钮的索引

复制代码 代码如下:

- (nsinteger)addbuttonwithtitle:(nsstring *)title;

[/code]

获取按钮标题

复制代码 代码如下:

- (nsstring *)buttontitleatindex:(nsinteger)buttonindex;

获取按钮数量

复制代码 代码如下:

@property(nonatomic,readonly) nsinteger numberofbuttons;

设置取消按钮的索引值

复制代码 代码如下:

@property(nonatomic) nsinteger cancelbuttonindex;

设置特殊标记

复制代码 代码如下:

@property(nonatomic) nsinteger destructivebuttonindex;

视图当前是否可见

复制代码 代码如下:

@property(nonatomic,readonly,getter=isvisible) bool visible;

下面是几种弹出方式,会根据风格不同展现不同的方式:
复制代码 代码如下:

- (void)showfromtoolbar:(uitoolbar *)view;
- (void)showfromtabbar:(uitabbar *)view;
- (void)showfrombarbuttonitem:(uibarbuttonitem *)item animated:(bool)animated ;
- (void)showfromrect:(cgrect)rect inview:(uiview *)view animated:(bool)animated ;
- (void)showinview:(uiview *)view;

使用代码将视图收回

复制代码 代码如下:

- (void)dismisswithclickedbuttonindex:(nsinteger)buttonindex animated:(bool)animated;


uiactionsheet代理方法

复制代码 代码如下:

- (void)actionsheet:(uiactionsheet *)actionsheet clickedbuttonatindex:(nsinteger)buttonindex;

点击按钮时触发的方法
复制代码 代码如下:

- (void)willpresentactionsheet:(uiactionsheet *)actionsheet;

视图将要弹出时触发的方法
复制代码 代码如下:

- (void)didpresentactionsheet:(uiactionsheet *)actionsheet;

视图已经弹出式触发的方法
复制代码 代码如下:

- (void)actionsheet:(uiactionsheet *)actionsheet willdismisswithbuttonindex:(nsinteger)buttonindex;

点击按钮后,视图将要收回时触发的方法
复制代码 代码如下:

- (void)actionsheet:(uiactionsheet *)actionsheet diddismisswithbuttonindex:(nsinteger)buttonindex;

点击按钮后,视图已经收回时触发的方法

上一篇:

下一篇: