标签:
警告对话框UIAlertView和等待提示器UIActivityIndicatorView:
1.UIAlertView简单一点就是弹框
2.就是所谓的菊花转圈圈
声明:注意@interface ViewController : UIViewController<UIAlertViewDelegate>
这个里面多了一个UIAlertViewDelegate代理
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIAlertViewDelegate>{
//定义一个警告对话框视图对象
UIAlertView * _alertView;
//等待提示对象
//当下载,或者加载比较大的文件时,可以显示此控件,处于提示等待状态
UIActivityIndicatorView * _activityIndicator;
}
@property(retain,nonatomic) UIAlertView * alertView;
@property(retain,nonatomic) UIActivityIndicatorView * activityIndicator;
@end
实现:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
//实现属性和成员变量的同步
@synthesize alertView =_alertView;
@synthesize activityIndicator=_activityIndicator;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
for(int i=0;i<2;i++){
UIButton * btn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(100, 100+100*i, 100, 40);
if(i==0){
[btn setTitle:@"警告对话框" forState:UIControlStateNormal];
}
else if(i==1){
[btn setTitle:@"等待指示器" forState:UIControlStateNormal];
}
btn.tag = 101+i;
[btn addTarget:self action:@selector(pressBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
}
-(void) pressBtn:(UIButton*) btn{
//警告对话框创建
//p1:对话框标题
//p2:提示信息
//p3:处理按钮事件的代理对象
//p4:取消按钮的文字,默认的索引为0;
//p5:其他按钮文字 ** otherButtonTitles:@"确定", nil]; 只有取消和确定按钮是横向排开
// otherButtonTitles:@"确定",@"确定1",@"确定2", nil];这样子就会全部纵向排开,索引依次是1,2,3.
//p6:...:添加其他按钮
//nil:表示按钮添加结束
if(btn.tag==101){
_alertView = [[UIAlertView alloc]initWithTitle:@"警告"
message:@"你的手机电量过低,请保存数据"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定", nil];
//显示对话框
[_alertView show];
}
//创建等待提示器,大伙都叫他菊花
else if(btn.tag==102){
//创建等待提示器,宽高不可变更
_activityIndicator =[[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(100, 300, 80, 80)];
//设定提示的风格:小灰,小白,大白
_activityIndicator.activityIndicatorViewStyle =UIActivityIndicatorViewStyleGray;//小灰
// _activityIndicator.activityIndicatorViewStyle=UIActivityIndicatorViewStyleWhite;//小白
//
// _activityIndicator.activityIndicatorViewStyle=UIActivityIndicatorViewStyleWhiteLarge;//大白
// self.view.backgroundColor=[UIColor blueColor];
[self.view addSubview:_activityIndicator];
//启动动画并显示
[_activityIndicator startAnimating];
//停止等待动画并隐藏
// [_activityIndicator stopAnimating];
}
}
//当点击对话框的按钮时,调用此函数
//p1:对话框对象本身
//p2:按钮的索引
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"index=%ld\n",buttonIndex);
}
//对话框即将消失,此函数被调用
-(void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex{
NSLog(@"即将消失!");
}
//对话框已经消失时,调用此函数
-(void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
NSLog(@"已经消失");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
iOS开发从入门到精通-- 警告对话框UIAlertView和等待提示器UIActivityIndicatorView
标签:
原文地址:http://blog.csdn.net/android_it/article/details/51979917