源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-10-05 11:22 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:iOS中的表单按钮选项UIActionSheet常用方法整理
什么是操作表单?看图: [img]http://files.jb51.net/file_images/article/201606/201661691629084.gif?201651691658[/img] 一看图就明白了,毋需多说。
[u]复制代码[/u] 代码如下:
UIActionSheet* mySheet = [[UIActionSheet alloc]                             initWithTitle:@"ActionChoose"                              delegate:self                              cancelButtonTitle:@"Cancel"                             destructiveButtonTitle:@"Destroy"                             otherButtonTitles:@"OK", nil];      [mySheet showInView:self.view]; 
与UIAlertView类似,我们也是在委托方法里处理按下按钮后的动作。记得在所委托的类加上UIActionSheetDelegate。
[u]复制代码[/u] 代码如下:
- (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支持的一种所谓的销毁按钮,对某户的某个动作起到警示作用, 比如永久性删除一条消息或者日志。如果你指定了一个销毁按钮他就会以红色高亮显示:
[u]复制代码[/u] 代码如下:
mySheet.destructiveButtonIndex=1; 
与导航栏类似,操作表单也支持三种风格 :
[u]复制代码[/u] 代码如下:
UIActionSheetStyleDefault              //默认风格:灰色背景上显示白色文字  UIActionSheetStyleBlackTranslucent     //透明黑色背景,白色文字  UIActionSheetStyleBlackOpaque          //纯黑背景,白色文字 
用法用例:
[u]复制代码[/u] 代码如下:
mySheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[b]常用方法和属性[/b] 显示ActionSheet方法: 1.在一个视图内部显示,可以用showInView
[u]复制代码[/u] 代码如下:
[mySheet showInView:self];
2.如果要将ActonSheet 与工具栏或者标签栏对齐,可以使用showFromToolBar或showFromTabBar
[u]复制代码[/u] 代码如下:
[mySheet showFromToolBar:toolbar]; [mySheet showFromTabBar:tabbar];
解除操作表单 用户按下按钮之后,Actionsheet就会消失——除非应用程序有特殊原因,需要用户按下做个按钮。用dismiss方法可令表单消失:
[u]复制代码[/u] 代码如下:
[mySheet dismissWithClickButtonIndex:1 animated:YES];  @property(nonatomic,copy) NSString *title;
设置标题
[u]复制代码[/u] 代码如下:
@property(nonatomic) UIActionSheetStyle actionSheetStyle;
添加一个按钮,会返回按钮的索引
[u]复制代码[/u] 代码如下:
- (NSInteger)addButtonWithTitle:(NSString *)title;
[/code] 获取按钮标题
[u]复制代码[/u] 代码如下:
- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
获取按钮数量
[u]复制代码[/u] 代码如下:
@property(nonatomic,readonly) NSInteger numberOfButtons;
设置取消按钮的索引值
[u]复制代码[/u] 代码如下:
@property(nonatomic) NSInteger cancelButtonIndex;
设置特殊标记
[u]复制代码[/u] 代码如下:
@property(nonatomic) NSInteger destructiveButtonIndex;
视图当前是否可见
[u]复制代码[/u] 代码如下:
@property(nonatomic,readonly,getter=isVisible) BOOL visible;
下面是几种弹出方式,会根据风格不同展现不同的方式:
[u]复制代码[/u] 代码如下:
- (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;
使用代码将视图收回
[u]复制代码[/u] 代码如下:
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
[b]UIActionSheet代理方法 [/b]
[u]复制代码[/u] 代码如下:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
点击按钮时触发的方法
[u]复制代码[/u] 代码如下:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet;
视图将要弹出时触发的方法
[u]复制代码[/u] 代码如下:
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet;
视图已经弹出式触发的方法
[u]复制代码[/u] 代码如下:
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex;
点击按钮后,视图将要收回时触发的方法
[u]复制代码[/u] 代码如下:
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;
点击按钮后,视图已经收回时触发的方法
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部