UIWindow *window=[UIApplication sharedApplication].keyWindow;
MBProgressHUD hud=[MBProgressHUD showMessage:@"加载中" toView:window];
UIView headhudview=[[UIView alloc]init];
// headhudview.backgroundColor=[UIColor redColor];
headhudview.frame=CGRectMake(0, 0, 40, 40);
hud.mode = MBProgressHUDModeCustomView;
hud.color=[UIColor clearColor];
hud.labelColor=[UIColor blackColor];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
//创建一个数组,数组中按顺序添加要播放的图片(图片为静态的图片)
NSMutableArray *imgArray = [NSMutableArray array];
for (int i=0; i<11; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"loading_%d",i+1]];
[imgArray addObject:image];
}
imageView.animationImages=imgArray;
imageView.animationDuration = 0.5;
imageView.animationRepeatCount = 0;
[imageView startAnimating];
[headhudview addSubview:imageView];
hud.customView=headhudview;
- (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
// NSLog(@"加载菊花");
if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
// 快速显示一个提示信息
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.labelText = message;
// 隐藏时候从父控件中移除
hud.removeFromSuperViewOnHide = YES;
// YES代表需要蒙版效果
hud.dimBackground = YES;
return hud;
}