UIAlertview UIActionSheet

2024-06-05 11:32
文章标签 uialertview uiactionsheet

本文主要是介绍UIAlertview UIActionSheet,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

UI控件篇——UIActionSheet(操作表)和UIAlertView(警告框)

2011-12-20 16:49 by 张智清, 1514 阅读, 3 评论, 收藏, 编辑

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。



这篇关于UIAlertview UIActionSheet的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1032932

相关文章

【我就看看不说话】UIAlertView

ViewController.h中的代码如下: [cpp]  view plain copy #import <UIKit/UIKit.h>      @interface ViewController : UIViewController<UIAlertViewDelegate>      @end   ViewController.m中的详

【我就看看不说话】 UIActionSheet

UIActionSheet是在iOS弹出的选择按钮项,可以添加多项,并为每项添加点击事件。 为了快速完成这例子,我们打开Xcode 4.3.2, 先建立一个single view application。然后再xib文件添加一个button,用来弹出sheet view。 1、首先在.h文件中实现协议 加代码的地方在@interface那行的最后添加<UIActionSheetDele

MMActionSheet介绍(自定义的UIActionSheet弹出框组件)

Introduction MMActionSheet 是一个简单的弹出选择框,使用纯swift编写,类似于微信的actionsheet MMActionSheet is an simple pop-up selection box(ActionSheet) written in pure Swift. Similar to the wechat actionsheet Rquiremen

UI-UIAlertView

#pragma mark - 1.基本用法UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Test" message:@"显示内容" delegate: nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];[alertView show]; #pragm

IOS】自定义UIAlertView样式,实现可替换背景和按钮 此博文包含图片此博文包含视频 (2012-10-24 10:23:25)

原文地址:http://blog.csdn.net/toss156/article/details/7552075】   UIAlertView 是一个十分常用的控件,网上也有好多类似的自定义AlertView的方法。但是感觉效果都不是很好,它们有的是在系统自带的上面添加文本框,也有的是完全自己用UIView来实现,还有的就是继承了UIAlertView 。

IOS开发:UIAlertView使用

UIAlertView是什么就不介绍了 1.基本用法 1 UIAlertView *view = [[UIAlertView alloc]initWithTitle:@"Test"    //标题 2                                               message:@"this is a alert view "   //显示内容 3

iOS安全之【 监听物理截图来自动生成截图并跳转到反馈页面进行显示】(截图内容包括系统的弹框视图UIAlertController和UIAlertView) | 蓄力计划

文章目录 引言I、反馈页面的开发步骤1.1、 监听截图通知1.2、 截图方法:1.2.1 方法一: 截图内容不包含_UIAlertControllerShimPresenterWindow 且不包含AlertView的方法:1.2.2 方法二:iOS根据视图尺寸获取视图截屏【截图内容包括UIAlertController和UIAlertView】 II demo源码2.1 本文的完整dem

iOS根据视图尺寸获取视图截屏【截图内容包括UIAlertController和UIAlertView】

文章目录 引言I、开发步骤1.1 第一步获取到alterView所在的window。1.2 第二步 遍历 window数组1.3 监听物理截图的时候,进行根据视图尺寸获取视图截屏进行显示 II、完整demo 引言 原文:https://kunnan.blog.csdn.net/article/details/113436136 https://kunnan.blog.csdn

IOS学习之UIActionSheet的使用

UIActionSheet是在iOS弹出的选择按钮项,可以添加多项,并为每项添加点击事件。 为了快速完成这例子,我们打开Xcode 4.3.2, 先建立一个single view application。然后再xib文件添加一个button,用来弹出sheet view。 1、首先在.h文件中实现协议 加代码的地方在@interface那行的最后添加<UIActionSheetDele

iOS UIActionSheet提示框

之前做过一个项目使用最新的提示框4s会默然的崩溃,于是又修改成最原始的UIActionSheet UIActionSheet使用情况具体如下 #import "ViewController.h"@interface ViewController ()<UIActionSheetDelegate>@property (nonatomic, strong)UIButton *button;@