一,效果图。
二,代码。
ViewController.m
class="cnblogs_code_copy" style="font-size: 18px">#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//在导航栏中显示等待对话框
[self showActivityIndicatorViewInNavigationItem];
}
//点击任何处,停止等待指示器
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//停止等待指示器,恢复导航栏
self.navigationItem.titleView = nil;
self.navigationItem.prompt = nil;
}
#pragma -mark -functions
//在导航栏中显示等待对话框
-(void) showActivityIndicatorViewInNavigationItem
{
UIActivityIndicatorView *aiview = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
self.navigationItem.titleView = aiview;
[aiview startAnimating];
self.navigationItem.prompt = @"数据加载中...";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end