DMProgressHUD是一款用于显示异步操作任务进度状态的视图工具。 该工具包含了目前较为主流的加载状态视图类型,后续会根据具体情况或需求进行迭代。 DMProgressHUD从设计层次的角度来看,其包含了5种展示模式:
pod 'DMProgressHUD'
;pod install
;#import <DMProgressHUD.h>
。#import "DMProgressHUD.h"
。注意:快捷调用使用默认的样式(Style-Dark)、动画(Animation-gradient)、遮盖(Mask-None)。
canonical-src="/Upload/Images/2017111012/6C0D7C44BDC40209.gif">
DMProgressHUD *hud = [DMProgressHUD showLoadingHUDAddedTo:self.view]; //hud.loadingType = DMProgressHUDLoadingTypeIndicator;//默认 hud.text = @"Here's info"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //异步耗时操作 [self doSomething]; dispatch_async(dispatch_get_main_queue(), ^{ //返回主线程隐藏HUD [hud dismiss]; }); });
DMProgressHUD *hud = [DMProgressHUD showLoadingHUDAddedTo:self.view]; hud.loadingType = DMProgressHUDLoadingTypeCircle; hud.text = @"Here's info"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //异步耗时操作 [self doSomething]; dispatch_async(dispatch_get_main_queue(), ^{ //返回主线程隐藏HUD [hud dismiss]; }); });
DMProgressHUD *hud = [DMProgressHUD showProgressHUDAddedTo:self.view]; //hud.progressType = DMProgressHUDProgressTypeCircle;//默认 hud.text = @"Here's info"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //异步耗时操作 [self doSomething]; dispatch_async(dispatch_get_main_queue(), ^{ //返回主线程隐藏HUD [hud dismiss]; }); });
DMProgressHUD *hud = [DMProgressHUD showProgressHUDAddedTo:self.view]; hud.progressType = DMProgressHUDProgressTypeSector; hud.text = @"Here's info"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //异步耗时操作 [self doSomething]; dispatch_async(dispatch_get_main_queue(), ^{ //返回主线程隐藏HUD [hud dismiss]; }); });
DMProgressHUD *hud = [DMProgressHUD showStatusHUDAddedTo:self.view statusType:DMProgressHUDStatusTypeSuccess]; hud.text = @"Here's info"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //异步耗时操作 [self doSomething]; dispatch_async(dispatch_get_main_queue(), ^{ //返回主线程隐藏HUD [hud dismiss]; }); });
DMProgressHUD *hud = [DMProgressHUD showStatusHUDAddedTo:self.view statusType:DMProgressHUDStatusTypeFail]; hud.text = @"Here's info"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //异步耗时操作 [self doSomething]; dispatch_async(dispatch_get_main_queue(), ^{ //返回主线程隐藏HUD [hud dismiss]; }); });
DMProgressHUD *hud = [DMProgressHUD showStatusHUDAddedTo:self.view statusType:DMProgressHUDStatusTypeWarning]; hud.text = @"Here's info"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //异步耗时操作 [self doSomething]; dispatch_async(dispatch_get_main_queue(), ^{ //返回主线程隐藏HUD [hud dismiss]; }); });
DMProgressHUD *hud = [DMProgressHUD showTextHUDAddedTo:self.view]; hud.text = @"Here's info"; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //异步耗时操作 [self doSomething]; dispatch_async(dispatch_get_main_queue(), ^{ //返回主线程隐藏HUD [hud dismiss]; }); });
DMProgressHUD *hud = [DMProgressHUD showHUDAddedTo:self.view]; hud.mode = DMProgressHUDModeCustom;//指定模式为自定义模式 hud.text = @"Here's info"; UIView *custom = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"person"]]; [hud setCustomView:custom width:180.0 height:180.0];//自定义View dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //异步耗时操作 [self doSomething]; dispatch_async(dispatch_get_main_queue(), ^{ //返回主线程隐藏HUD [hud dismiss]; }); });
以上所列举关于DMProgressHUD的功能介绍,用户可以通过 运行Demo 查看到相应的效果。除此之外,用户还可以对HUD的 图文间距、颜色等 进行自定义,可以在 DMProgressHUD.h 文件查看更多的API详细介绍。
更多文章:简书
联系方式(Email): damonmok1216@gmail.com。