UIAlertView
1.Title
获取或设置UIAlertView上的标题。
2.Message
获取或设置UIAlertView上的消息
UIAlertView *alertView = [[UIAlertViewalloc] initWithTitle:@"Title"message:@"message"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定", nil];
alertView.title = @"T";
alertView.message = @"M";
[alertView show];

3.numberOfButtons (只读)
返回UIAlertView上有多少按钮.
UIAlertView *alertView = [[UIAlertViewalloc] initWithTitle:@"Title"message:@"message"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定", nil];
NSLog(@"%d",alertView.numberOfButtons);
[alertView show];

4.cancelButtonIndex
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"
message:@"请选择一个按钮:"
delegate:nil
cancelButtonTitle:@"取消"
otherButtonTitles:@"按钮一", @"按钮二", @"按钮三",nil];
[alert show];
NSLog(@"UIAlertView中取消按钮的角标是%d",alert.cancelButtonIndex);
效果:

注意不要认为取消按钮的角标是4,“取消”,“按钮一”,“按钮二”,“按钮三”的索引buttonIndex分别是0,1,2,3
5.alertViewStyle
5.1UIAlertViewStyleLoginAndPasswordInput
UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"产品信息展示" message:p.namedelegate:nilcancelButtonTitle:@"取消"otherButtonTitles:@"确定", nil];
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
// 弹出UIAlertView
[alert show];

5.2UIAlertViewStylePlainTextInput
UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"产品信息展示" message:p.namedelegate:nilcancelButtonTitle:@"取消"otherButtonTitles:@"确定", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
// 弹出UIAlertView
[alert show];

5.3UIAlertViewStyleSecureTextInput
UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"产品信息展示" message:p.namedelegate:nilcancelButtonTitle:@"取消"otherButtonTitles:@"确定", nil];
alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
// 弹出UIAlertView
[alert show];

6.- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex
返回textFieldIndex角标对应的文本框。
取出文本框文字
7.手动的取消对话框
[alertdismissWithClickedButtonIndex:0 animated:YES];
8.delegate
作为UIAlertView的代理,必须遵守UIAlertViewDelegate。
1.当点击UIAlertView上的按钮时,就会调用,并且当方法调完后,UIAlertView会自动消失。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
2.当UIAlertView即将出现的时候调用
- (void)willPresentAlertView:(UIAlertView *)alertView;
3.当UIAlertView完全出现的时候调用
- (void)didPresentAlertView:(UIAlertView *)alertView;
4.当UIAlertView即将消失的时候调用
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex;
5.当UIAlertView完全消失的时候调用
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
9.注意UIAlertView调用show显示出来的时候,系统会自动强引用它,不会被释放。
10.为UIAlertView添加子视图
在为UIAlertView对象太添加子视图的过程中,有点是需要注意的地方,如果删除按钮,也就是取消UIAlerView视图中所有的按钮的时候,可能会导致整个显示结构失衡。按钮占用的空间不会消失,我们也可以理解为这些按钮没有真正的删除,仅仅是他不可见了而已。如果在UIAlertview对象中仅仅用来显示文本,那么,可以在消息的开头添加换行符(@"\n)有助于平衡按钮底部和顶部的空间。
下面的代码用来演示如何为UIAlertview对象添加子视图的方法。
UIAlertView*alert =
[[UIAlertView alloc]initWithTitle:@"请等待"
message:nil
delegate:nil
cancelButtonTitle:nil
otherButtonTitles: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];

11.UIAlertView小例子
UIAlertView默认情况下所有的text是居中对齐的。那如果需要将文本向左对齐或者添加其他控件比如输入框时该怎么办呢?不用担心, iPhone SDK还是很灵活的,有很多delegate消息供调用程序使用。所要做的就是在
- (void)willPresentAlertView:(UIAlertView *)alertView
中按照自己的需要修改或添加即可,比如需要将消息文本左对齐,下面的代码即可实现:
-(void)
willPresentAlertView:(UIAlertView *)alertView
{
for( UIView * view in alertView.subviews )
{
if(
[view isKindOfClass:[UILabel class]] )
{
UILabel*
label = (UILabel*) view;
label.textAlignment=UITextAlignmentLeft;
}
}
}


UIAlertView的更多相关文章
- 弹框控件 UIAlertView UIActionSheet
// 创建弹框 从底部弹出,一般用于危险操作 UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"恭喜通关" ...
- 自定义一个类似UIAlertView的弹出框
这个是和UIAlertView类似,但是可以自定义view的样式废话不多说,上代码: 首先第一步:创建一个继承自View的类如: #import <UIKit/UIKit.h> @clas ...
- UIAlertView和UIActivityIndicatorView的使用
UIAlertView用来显示一个对话框,可以设置对话框的标题.文案.按钮的个数和文案,也可以通过实现delegate来监听按钮的的点击操作. 使用UIAlertView时需要注意: self.ale ...
- 【代码笔记】iOS-带输入框的UIAlertView
一,效果图. 二,代码. //点击任何处,弹出输入框 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UIAlertV ...
- iOS开发之UIAlertView与UIAlertController的详尽用法说明
本文将从四个方面对IOS开发中UIAlertView与UIAlertController的用法进行讲解: 一.UIAlertView与UIAlertController是什么东东? 二.我们为什么要用 ...
- iOS UIAlertView添加输入框
这玩意有时不用就忘,还是记录一下吧 添加: UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"新建文件夹" mes ...
- UILabel UISwitch UISegmentedControl UIAlertView
基础小控件 /***************************************UIlabel*************************************/ UILabel ...
- UIAlertView 与 UIActionSheet (提示用户)的使用方法
UIAlertView 提示用户 帮助用户选择框 // UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:@"警 ...
- UIAlertView、 UIActionSheet
一.UIAlertView. UIActionSheet都是ios系统自带的弹出式对话框,当UIAlertView或UIActionSheet弹出来时用户无法与应用界面中的其它控件交互,UIAlert ...
- IOS开发UI基础 UIAlertView的属性
UIAlertView1.Title获取或设置UIAlertView上的标题. 2.Message获取或设置UIAlertView上的消息 UIAlertView *alertView = [[UIA ...
随机推荐
- c#String的不变特性,可读但不可写性
谈到字符串,大家自然觉得简单,但是总是有一些小的问题隐约出现,下面我就系统的说一下字符串的问题,有说不到日后再予补充. 1,首先String是一个类,string只是String类的一个别名,别名的意 ...
- win7锁定到任务栏的路径在哪里
You can find pinned apps in: %AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar ...
- NV Perf Kit
https://developer.nvidia.com/gameworksdownload#?dn=perfkit-4-0-0 Title Version Release Date PerfKit ...
- cURL 学习笔记与总结(5)用 cURL 访问 HTTPS 资源
<?php $curlobj = curl_init(); // 初始化 curl_setopt($curlobj, CURLOPT_URL, "https://ajax.aspnet ...
- MVC设计模式
随着Web应用的商业逻辑包含逐渐复杂的公式分析计算.决策支持等,使客户机越 来越不堪重负,因此将系统的商业分离出来.单独形成一部分,这样三层结构产生了. 其中‘层’是逻辑上的划分. 三层体系结构是将整 ...
- 纯css下拉菜单的制作
通过观察下拉菜单的过程,发现有两种状态,一种是鼠标没有hover时,一种是鼠标hover时. 主菜单hover时,显示子菜单:主菜单没有hover时,不显示子菜单 <!DOCTYPE html& ...
- CLR调试报错“Visual Studio远程调试监视器 (MSVSMON.EXE) 的 64 位版本无法调试 32 位进程或 32 位转储。请改用 32 位版本”的解决
Win7 64位电脑上进行visual studio的数据库项目的CLR存储过程进行调试时,报错: ---------------------------Microsoft Visual Studio ...
- 【转】用树莓派搭建web服务器
本文将详细介绍如何在树莓派上配置服务器,和<教你在Xubuntu上搭建LAMP服务器>有些类似,多了一些介绍在树莓派上的不同步骤的地方. 这种服务器的配置被称为LAMP,是最流行的服务器配 ...
- Struts Upload上传文件
1.Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.te ...
- Qt from Linux to Windows target
45down voteaccepted Just use M cross environment (MXE). It takes the pain out of the whole process: ...