UIAlertView
1.Title
获取或设置UIAlertView上的标题。

2.Message
获取或设置UIAlertView上的消息

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alertView.title = @"T";
    alertView.message = @"M";

[alertView show];

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

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

注意不要认为取消按钮的角标是4,“取消”,“按钮一”,“按钮二”,“按钮三”的索引buttonIndex分别是0,1,2,3

5. alertViewStyle
5.1 UIAlertViewStyleLoginAndPasswordInput
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"产品信息展示" message:p.name delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    
// 弹出UIAlertView
 [alert show];

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

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

6. - (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex
返回textFieldIndex角标对应的文本框。
取出文本框文字
7.手动的取消对话框
[alert dismissWithClickedButtonIndex: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;
            }
      }
}

IOS开发UI基础 UIAlertView的属性的更多相关文章

  1. IOS开发UI基础UITextFidle相关属性

    UITextFidle相关属性 •    enablesReturnKeyAutomatically默认为No,如果设置为Yes,文本框中没有输入任何字符的话,右下角的返回按钮是disabled的. ...

  2. IOS开发UI基础UIImagePickerController的属性

    UIImagePickerController 1.+(BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType ...

  3. IOS开发UI基础UITableView的属性

    UITableView UITableView内置了两种样式:UITableViewStylePlain,UITableViewStyleGrouped <UITableViewDataSour ...

  4. IOS开发UI基础 UIDatePicker的属性

    UIDatePicker        •    Locale设置DatePicker的地区,即设置DatePicker显示的语言.// 1.跟踪所有可用的地区,取出想要的地区    NSLog(@& ...

  5. IOS开发UI基础UIPageControl的属性

    UIPageControl 常见属性: •    numberOfPages // 设置有多少页 默认为0 [pageControl setNumberOfPages:kImageCount]; •  ...

  6. IOS开发UI基础UIPikerView的属性

    UIPikerView的属性 1. numberOfComponents:返回UIPickerView当前的列数NSInteger num = _pickerView.numberOfComponen ...

  7. IOS开发UI基础UITextView相关属性

    UITextView相关属性 •    text: 设置textView中文本_textView.text = @"Now is the time for all good develope ...

  8. IOS开发UI基础UIActivityIndicatorView的属性

    UIActivityIndicatorView 1.activityIndicatorViewStyle设置指示器的样式UIActivityIndicatorViewStyleWhiteLarge U ...

  9. iOS开发UI基础—手写控件,frame,center和bounds属性

    iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...

随机推荐

  1. J2EE Web开发入门—通过action是以传统方式返回JSON数据

    关键字:maven.m2eclipse.JSON.Struts2.Log4j2.tomcat.jdk7.Config Browser Plugin Created by Bob 20131031 l ...

  2. BootStrap安装

    1. 安装Node.js    http://nodejs.org/download/ 2. 加速NPM安装    npm install -g cnpm --registry=http://r.cn ...

  3. LeetCode:Roman to Integer,Integer to Roman

    首先简单介绍一下罗马数字,一下摘自维基百科 罗马数字共有7个,即I(1).V(5).X(10).L(50).C(100).D(500)和M(1000).按照下述的规则可以表示任意正整数.需要注意的是罗 ...

  4. JSON编码格式提交表单数据详解

    以JSON编码格式提交表单数据是HTML5对WEB发展进化的又一大贡献,以前我们的HTML表单数据是通过key-value方式传输的服务器端,这种形式的传输对数据组织缺乏管理,形式十分原始.而新出现的 ...

  5. offsetWidth、clientWidth、width、scrollWidth区别及js与jQuery获取的方式

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. python数据结构之图深度优先和广度优先

    首先有一个概念:回溯 回溯法(探索与回溯法)是一种选优搜索法,按选优条件向前搜索,以达到目标.但当探索到某一步时,发现原先选择并不优或达不到目标,就退回一步重新选择,这种走不通就退回再走的技术为回溯法 ...

  7. [原]quick2.25精灵变灰

    由于quick2.25没有导出shader相应的接口,所以2.25无法直接使用shader. 本文简单介绍如何导出相应接口,同时教大家使用shader 实现精灵变灰 一.编写静态函数,以供导出使用(直 ...

  8. 气球或者泡泡向上飘动 jQuery插件

    圣诞.元旦要来了,公司以往基本每个月至少要搞一两款手机小游戏来宣传产品,这次也不例外!! 之前做过,按压柚子.许愿.吃柚子等等小游戏,这次是做个那种 气球向上飘动,戳破气球,随机获取奖品.如下图: 手 ...

  9. dell新服务器安装系统

    公司新采购的dell 630服务器,但是第一次安装操作系统的时候比较麻烦,每次都要重新琢磨下. 现在记录一下,以供下次参考 1.插入服务器自带光盘,设置CD启动,选择部署OS 2.配置raid,然后插 ...

  10. SAP ECC FI配置文档

    SAP ECC 6.0 Configuration Document Financial Accounting (FI) Table of Content TOC \O "1-2" ...