iOS开发从入门到精通-- 警告对话框UIAlertView和等待提示器UIActivityIndicatorView
程序员文章站
2022-10-31 15:10:28
警告对话框uialertview和等待提示器uiactivityindicatorview:
1.uialertview简单一点就是弹框
2.就是所谓的菊花转圈圈
声明:注意@interface...
警告对话框uialertview和等待提示器uiactivityindicatorview:
1.uialertview简单一点就是弹框
2.就是所谓的菊花转圈圈
声明:注意@interface viewcontroller : uiviewcontroller
喎?https: www.2cto.com/kf/ware/vc/"="" target="_blank" class="keylink">vcd4ncjxwcmugy2xhc3m9"brush:java;">
#import
实现:
#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喎?https:>
下一篇: 关于Form表单的Input输入对象