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.3 UIAlertViewStyleSecureTextInput

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开发新手送点福利,简述UIAlertView的属性和用法的更多相关文章

  1. 给iOS开发新手送点福利,简述UIImagePickerController的属性和用法

    1.+(BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType;         // 检查指定源是否在设备上 ...

  2. 给iOS开发新手送点福利,简述UITableView的属性和用法

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

  3. 给iOS开发新手送点福利,简述UIView的属性和用法

    UIView 1.alpha 设置视图的透明度.默认为1. // 完全透明 view.alpha = 0; // 不透明 view.alpha = 1; 2.clipsToBounds // 默认是N ...

  4. 给iOS开发新手送点福利,简述UITextField的属性和用法

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

  5. 给iOS开发新手送点福利,简述UILabel的属性和用法

    UILabel属性 1.text:设置标签显示文本. label.text = @"我是Label"; 2.attributedText:设置标签属性文本. NSString *t ...

  6. 给iOS开发新手送点福利,简述UIPikerView的属性和用法

    1.   numberOfComponents:返回UIPickerView当前的列数 NSInteger num = _pickerView.numberOfComponents; NSLog( @ ...

  7. 给iOS开发新手送点福利,简述UIScrollView的属性和用法

    UIScrollView 1.   contentOffset 默认CGPointZero,用来设置scrollView的滚动偏移量. // 设置scrollView的滚动偏移量 scrollView ...

  8. 给iOS开发新手送点福利,简述UIPageControl的属性和用法

    UIPageControl 1.   numberOfPages // 设置有多少页 默认为0 [pageControl setNumberOfPages:kImageCount]; 2.   cur ...

  9. 给iOS开发新手送点福利,简述UISegment的属性和用法

    UISegment属性 1.segmentedControlStyle 设置segment的显示样式. typedef NS_ENUM(NSInteger, UISegmentedControlSty ...

随机推荐

  1. redis高可用 - redis集群

    redis-sentinel方案提供了单点的高可用解决方案,但是当数据量和业务量极速增长时,单点的reids不可能无限的纵向扩容(增大内存),这个时候就需要redis有集群的能力来扛. redis集群 ...

  2. Python——列表表达式

    https://www.cnblogs.com/xuyuanyuan123/p/6718403.html

  3. gcd 与 扩gcd 总结

    gcd 定理的证明: 模板: ll gcd(ll a,ll b) { ) return a; else return gcd(b,a%b); } 扩gcd证明: 模板: ll extgcd(ll a, ...

  4. 99. Recover Binary Search Tree -- 找到二叉排序树中交换过位置的两个节点

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  5. 管道 && 消息队列 && 共享内存

    http://blog.csdn.net/piaoairy219/article/details/17333691 1. 管道 管道的优点是不需要加锁. 缺点是默认缓冲区太小,只有4K. 一个管道只适 ...

  6. 无线基站侧的信令风暴根因——频繁的释放和连接RRC产生大量信令、设备移动导致小区重选信令增加、寻呼信令多

    全局思维(核心网和无线基站侧都会有信令风暴): LTE网络系统可能出现信令风暴的原因,大致可以总结出以下几点: 1.网络架构的变化,导致4G核心网信令流量较2G/3G大幅增加 a)架构扁平化:LTE网 ...

  7. HDU 5186 zhx's submissions 模拟,细节 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=5186 题意是分别对每一位做b进制加法,但是不要进位 模拟,注意:1 去掉前置0 2 当结果为0时输出0,而不是全 ...

  8. CF 274D Lovely Matrix 拓扑排序,缩点 难度:2

    http://codeforces.com/problemset/problem/274/D 这道题解题思路: 对每一行统计,以小值列作为弧尾,大值列作为弧头,(-1除外,不连弧),对得到的图做拓扑排 ...

  9. [批处理]NetstatFilter快速查找端口被占用问题

    前言 准确的说,他是一个网络连接端口查看器,可以根据进程查端口,也可以根据端口查进程.期初是因在使用Fiddler的时候发现无法启动,提示端口被占用,但是由不知道用什么方法才能找到是哪个程序占用的Fi ...

  10. 理解 Socket

    原文链接 题外话 前几天和朋友聊天,朋友问我怎么最近不写博客了,一个是因为最近在忙着公司使用的一些控件的开发,浏览器兼容性搞死人 但主要是因为这段时间一直在看html5的东西,看到web socket ...