1.MBProgressHUD
/*
MBProgressHUD 是对象方法
先创建一个全局的MBProgressHUD
MBProgressHUD *HUD;
导入头文件,实现协议
点击进去可以看到方法
这里简单举例子
*/
//方式1.直接在View上show
HUD = [MBProgressHUDshowHUDAddedTo:self.viewanimated:YES];
HUD.delegate =self;
//常用的设置
//小矩形的背景色
HUD.color = [UIColorclearColor];//这儿表示无背景
//显示的文字
HUD.labelText =@"Test";
//细节文字
HUD.detailsLabelText =@"Test detail";
//是否有庶罩
HUD.dimBackground =YES;
[HUDhide:YESafterDelay:2];
//只显示文字
MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.viewanimated:YES];
hud.mode =MBProgressHUDModeText;
hud.labelText =@"Some message...";
hud.margin =10.f;
hud.yOffset =150.f;
hud.removeFromSuperViewOnHide =YES;
[hudhide:YES afterDelay:3];
//方式2.initWithView
//use block
HUD = [[MBProgressHUDalloc] initWithView:self.view];
[self.viewaddSubview:HUD];
HUD.labelText =@"Test";
[HUDshowAnimated:YESwhileExecutingBlock:^{
NSLog(@"%@",@"do somethings....");
[selfdoTask];
} completionBlock:^{
[HUDremoveFromSuperview];
}];
//圆形进度条
HUD = [[MBProgressHUDalloc] initWithView:self.view];
[self.viewaddSubview:HUD];
HUD.mode =MBProgressHUDModeAnnularDeterminate;
HUD.delegate =self;
HUD.labelText =@"Loading";
[HUDshowWhileExecuting:@selector(myProgressTask)onTarget:selfwithObject:nilanimated:YES];
//自定义view
HUD = [[MBProgressHUDalloc] initWithView:self.view];
HUD.customView = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"37x-Checkmark.png"]];
// Set custom view mode
HUD.mode =MBProgressHUDModeCustomView;
HUD.delegate =self;
HUD.labelText =@"Completed";
[HUDshow:YES];
[HUDhide:YESafterDelay:3];
}
#pragma mark HUD的代理方法,关闭HUD时执行
-(void)hudWasHidden:(MBProgressHUD *)hud
{
[hud removeFromSuperview];
hud =nil;
}
-(void)doTask
{
//你要进行的一些逻辑操作
sleep(2);
}
//进度条
-(void) myProgressTask{
float progress = 0.0f;
while (progress < 1.0f) {
progress +=0.01f;
HUD.progress = progress;
usleep(50000);
}
}
2.MMProgressHUD
-(void)btnAction
{
/*
MMProgressHUD 是类方法
导入头文件直接使用加方法就可以了
点击进去可以看到方法
这里简单举例子
*/
[MMProgressHUDshow];
[MMProgressHUDshowWithTitle:@"yes"];
[MMProgressHUDshowWithStatus:@"hello"];
}
3.SVProgressHUD
-(void)btnAction
{
/*
SVProgressHUD 是类方法
导入头文件直接使用加方法就可以了
点击进去可以看到方法
这里简单举例子
*/
[SVProgressHUDshow];
[SVProgressHUDshowErrorWithStatus:@"error"];
[SVProgressHUDshowWithStatus:@"success"];
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
[self performSelector:@selector(increateProgress) withObject:nil afterDelay:0.3];
}
//进度条
staticfloat progressValue =0.0f;
- (void)increateProgress
{
progressValue +=0.1;
[SVProgressHUDshowProgress:progressValue status:@"加载中"];
if (progressValue <1) {
[self performSelector:@selector(increateProgress) withObject:nil afterDelay:0.3];
}else{
[self performSelector:@selector(dismiss:)withObject:nil afterDelay:0.4];
}
}
-(void)dismiss:(id)sender
{
[SVProgressHUD dismiss];
}