iOS UIAlertView自动关闭功能

时间:2022-10-29 12:01:02

一,效果图。

iOS UIAlertView自动关闭功能

二,代码。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
rootviewcontroller.h
#import <uikit/uikit.h>
@interface rootviewcontroller : uiviewcontroller
<uialertviewdelegate>
@end
rootviewcontroller.m
- (void)viewdidload
{
 [super viewdidload];
 // do any additional setup after loading the view.
 //alert
 uialertview *alert=[[uialertview alloc]initwithtitle:nil message:@"一个可以自动关闭的alert窗口" delegate:self cancelbuttontitle:nil otherbuttontitles:nil, nil];
 [alert show];
 //显示框
 uiactivityindicatorview *indicator = [[uiactivityindicatorview alloc] initwithactivityindicatorstyle:uiactivityindicatorviewstylewhitelarge];
 indicator.backgroundcolor=[uicolor redcolor];
 indicator.center = cgpointmake(alert.bounds.size.width/2, alert.bounds.size.height-40.0);
 [indicator startanimating];
 [alert insertsubview:indicator atindex:0];
 //定时器
 [nstimer scheduledtimerwithtimeinterval:3.0f target:self selector:@selector(dismissalert:) userinfo:[nsdictionary dictionarywithobjectsandkeys:alert, @"alert", @"testing ", @"key" ,nil] repeats:no];
}
//alert 自动消失
-(void) dismissalert:(nstimer *)timer{
 uialertview *alert = [[timer userinfo] objectforkey:@"alert"];
 [alert dismisswithclickedbuttonindex:0 animated:yes];
}

以上所述是小编给大家介绍的ios uialertview自动关闭,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:http://www.cnblogs.com/yang-guang-girl/archive/2017/06/20/7052794.html