广

IOS开发

  • IOS开发
  • android开发
  • PHP编程
  • JavaScript
  • ASP.NET
  • ASP编程
  • JSP编程
  • Java编程
  • 易语言
  • Ruby编程
  • Perl编程
  • AJAX
  • 正则表达式
  • C语言
  • 编程开发

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

    2018-04-07 07:50:26 次阅读 稿源:互联网
    广告

    什么是操作表单?看图:

    一看图就明白了,毋需多说。
    代码如下:

    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;

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

    一起学吧部分文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与一起学吧进行文章共享合作。

    广告
    广告
    广告