iOS之非同步任務進度載入提示工具,ios進度載入

來源:互聯網
上載者:User

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。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.