iOS UIAlertView自动关闭功能
更新时间:2017年06月20日 11:10:18 作者:弦外雨
这篇文章主要介绍了iOS UIAlertView自动关闭,需要的朋友可以参考下
一,效果图。

二,代码。
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自动关闭,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
相关文章
iOS实现UIScrollView的无限轮播功能(原理)详解
在现在的一些App中常常见到图片轮播器,一般用于展示广告、新闻等数据,下面这篇文章主要给大家介绍了关于iOS实现UIScrollView的无限轮播功能(原理)的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考下2018-09-09
详解iOS tableViewCell自适应高度 第三发类库
在github中有许多大牛封装好的第三发类库,其中有个自适应cell高度的类库。接下来通过本文给大家介绍iOS tableViewCell自适应高度 第三发类库,需要的朋友参考下2016-04-04
iOS使用pageViewController实现多视图滑动切换
这篇文章主要为大家详细介绍了iOS使用pageViewController实现多视图滑动切换,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2018-06-06
iOS的UIColor类与其相关类之间的区别及判断相等的方法
这篇文章主要介绍了iOS的UIColor类与其相关类之间的区别及判断相等的方法,主要是对比了CGColor和CIColor,需要的朋友可以参考下2015-10-10


最新评论