zoukankan      html  css  js  c++  java
  • UI控件篇——UIActionSheet(操作表)和UIAlertView(警告框)

    UIActionSheet用于迫使用户在两个或更多的选项之间进行选择的模式视图。操作表是从屏幕底部弹出,显示一系列按钮供用户选择,用户只有单击一个按钮后才能继续使用应用程序。(可以理解为桌面应用系统的右键菜单的功能)

    UIAlertView警告默认是以蓝色圆角矩形形式显示在屏幕中央,警告框可显示一个或多个按钮。

    为了让控制器类充当操作表的委托,控制器需要遵从UIActionSheetDelegate协议。

    一、UIActionSheet(操作表)的创建

    带标题名称来初始化创建UIActionSheet表:initWithTitle
          initWithTitle: delegate: cancelButtonTitle: destructiveButtonTitle: otherButtonTitles:

    对于在某个视图中显示出创建好的UIActionSheet,则要用到showInView:这个方法。当我们是采用自定义创建的操作表时,则该操作表中的按钮必须实现UIActionSheetDelegate协议函数,以控制在点击按钮之后的操作。如:

    - (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(buttonIndex == 0) {
    //NSLog(@"ok");
    }
    else {
    //NSLog(@"cancel");
    }
    }

    二、UIAlertView (警告框)的创建

    带标题名称来初始化创建UIAlertView警告:initWithTitle
          initWithTitle: message: delegate: cancelButtonTitle: otherButtonTitles: 
    要显示创建好的UIAlertView警告框只要调用show方法即可。自定义警告框中的按钮要实现UIAlertViewDelegate协议函数,总之,UIAlertView实例要响应按钮点击,至少需要该委托的支持。此处可以控制在点击按钮之后的操作。如:

    - (void)alertView: (UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    //use "buttonIndex" to decide your action
    }

    注意:使用非自动释放警告框时,要确保有一个委托负责在用户点击按钮时释放警告框!!

    警告框扩展应用:给UIAlertView添加子视图(示例为添加一个活动指示符)

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitle:nil];[alert show];

    UIActivityIndicatorView *activeView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    activeView.center = CGPointMake(alert.bounds.size.width/2.0f, alert.bounds.size.height-40.0f);
    [activeView startAnimating];
    [alert addSubview:activeView];
    [activeView release];
    [alert release];

    // Auto dismiss after 3 seconds for this example
    [self performSelector:@selector(performDismiss) withObject:nil afterDelay:3.0f];

    当然若是自定义创建的是无按钮警告框则必须实现手动让其消失(因为它一般不会正确回调委托方法,则不会自动消失)。具体就是调用dismissWithClickedButton Index: animated:来实现。

    - (void)performDismiss {
    [alert dismissWithClickedButton Index:0 animated:NO];
    }

    另外UIActivityIndicatorView实例提供了很多轻量级视图,它们显示一个标准的旋转进度轮。其中不同风格的UIActivityIndicatorView类使用场合不同。UIActivityIndicatorViewStyleWhite和UIActivityIndicatorViewStyleGray的大小是20x20像素。而UIActivityIndicatorViewStyleWhiteLarge提供了一个最大、最清晰的指示器,为37x37像素。通过发送startAnimating启动指示器。要停止则调用stopAnimating。



  • 相关阅读:
    (转)投票系统,更改ip刷票
    图像判断(转)
    第06组 Alpha事后诸葛亮
    第06组 Alpha冲刺(6/6)
    2019 SDN上机第4次作业
    第06组 Alpha冲刺(5/6)
    第06组 Alpha冲刺(4/6)
    第06组 Alpha冲刺(3/6)
    第06组 Alpha冲刺(2/6)
    2019 SDN上机第3次作业
  • 原文地址:https://www.cnblogs.com/lovecode/p/2294563.html
Copyright © 2011-2022 走看看