UIAlertView---iOS-Apple苹果官方文档翻译

本系列全部开发文档翻译连接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址html

 

UIAlertViewpost

 

//转载请注明出处--本文永久连接:http://www.cnblogs.com/ChenYilong/p/3495704.htmlurl


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];
pastedGraphic.png
3.numberOfButtons (只读)
返回UIAlertView上有多少按钮.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"肯定", nil];
   
 NSLog(@"%d",alertView.numberOfButtons);
[alertView
 show];
pastedGraphic_1.pngspa

//转载请注明出处--本文永久连接:http://www.cnblogs.com/ChenYilong/p/3495704.html

4.cancelButtonIndex
   UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                                 
 message:@"请选择一个按钮:"
                                                
 delegate:nil
                                        
cancelButtonTitle:@"取消"
                                       
 otherButtonTitles:@"按钮一", @"按钮二", @"按钮三",nil];
   [alert
 show];
NSLog(@"UIAlertView中取消按钮的角标是%d",alert.cancelButtonIndex);
效果:
pastedGraphic_2.png
注意不要认为取消按钮的角标是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];

pastedGraphic_3.png

5.2 UIAlertViewStylePlainTextInput
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"产品信息展现" message:p.name delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"肯定", nil];
   
alert.
alertViewStyle = UIAlertViewStylePlainTextInput;
   
// 弹出UIAlertView
 [alert
 show];
pastedGraphic_4.png
//转载请注明出处--本文永久连接:http://www.cnblogs.com/ChenYilong/p/3495704.html翻译

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角标对应的文本框。
取出文本框文字
 pastedGraphic_5.png
7.手动的取消对话框
[alert dismissWithClickedButtonIndex:0 animated:YES];
//技术博客http://www.cnblogs.com/ChenYilong/   新浪微博http://weibo.com/luohanchenyilong  
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; 
//转载请注明出处--本文永久连接:http://www.cnblogs.com/ChenYilong/p/3495704.html3d


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];  
pastedGraphic_6.png
 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;
            }
      }
}
pastedGraphic_7.png

//技术博客http://www.cnblogs.com/ChenYilong/   新浪微博http://weibo.com/luohanchenyilong代理

//转载请注明出处--本文永久连接:http://www.cnblogs.com/ChenYilong/p/3495704.html code

 本文对应pdf文档下载连接,猛戳—>:https://www.evernote.com/shard/s227/sh/ff5a52fc-c82d-4686-86ff-850874ec73fb/28a5a4c877c7337666941d6b078c1b11htm

本系列全部开发文档翻译连接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址对象

相关文章
相关标签/搜索