服务器之家

服务器之家 > 正文

iOS UIAlertView自动关闭功能

时间:2021-03-18 16:00     来源/作者:弦外雨

一,效果图。

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
 

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部