手机
当前位置:查字典教程网 >编程开发 >IOS开发 >iOS中的表单按钮选项UIActionSheet常用方法整理
iOS中的表单按钮选项UIActionSheet常用方法整理
摘要:什么是操作表单?看图:一看图就明白了,毋需多说。复制代码代码如下:UIActionSheet*mySheet=[[UIActionSheet...

什么是操作表单?看图:

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

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

复制代码 代码如下:

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;

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

【iOS中的表单按钮选项UIActionSheet常用方法整理】相关文章:

详解iOS中UIView的layoutSubviews子视图布局方法使用

iOS中的UISlider滑块组件用法总结

iOS中的UIKeyboard键盘视图使用方法小结

iOS中的UIStepper数值加减器用法指南

iOS开发中导航控制器的基本使用教程

iOS开发中WebView的基本使用方法简介

iOS App开发中的UISegmentedControl分段组件用法总结

iOS开发中UIImageView控件的常用操作整理

iOS开发中使用CoreLocation框架处理地理编码的方法

iOS开发中实现显示gif图片的方法

精品推荐
分类导航