iOS之非同步任務進度載入提示工具,ios進度載入
一、簡介
DMProgressHUD是一款用於顯示非同步作業任務進度狀態的視圖工具。 該工具包含了目前較為主流的載入狀態檢視類型,後續會根據具體情況或需求進行迭代。 DMProgressHUD從設計層次的角度來看,其包含了5種展示模式:
二、匯入(Platform : ios >= 8.0)方案1:CocoaPods方案2:直接匯入到工程三、快捷調用
注意:快捷調用使用預設的樣式(Style-Dark)、動畫(Animation-gradient)、遮蓋(Mask-None)。
1.Loading Mode1.1 Loading-Indicator
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]; }); });
1.2 Loading-Circle
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]; }); });
2.Progress Mode2.1 Progress-Circle
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]; }); });
2.2 Progress-Sector
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]; }); });
3.Status Mode3.1 Success
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]; }); });
3.2 Fail
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]; }); });
3.3 Warning
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]; }); });
4.Text Mode4.1 Text
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]; }); });
5.Custom Mode5.1 Custom
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。