zoukankan      html  css  js  c++  java
  • iOS 第三方类库之MBProgressHUD

    github链接地址

    MBProgressHUD是一个开源的第三方类库实现了很多种样式的提示框,类似Activity indicator,使用上简单、方便,并且可以对显示的内容进行自定义,功能很强大,很多项目中都有使用到

          MBProgressHUD is an iOS drop-in class that displays a translucent HUD with an indicator and/or labels while work is being done in a background thread. The HUD is meant as a replacement for the undocumented, private UIKit UIProgressHUD with some additional features.

     

    Usage

     

    The main guideline you need to follow when dealing with MBProgressHUD while running long-running tasks is keeping the main thread work-free, so the UI can be updated promptly. The recommended way of using MBProgressHUD is therefore to set it up on the main thread and then spinning the task, that you want to perform, off onto a new thread.

    程序在执行一个长时间任务的时候(例如网络请求),可以使用该类库在主窗口中添加一个提示框显示进度或者相关的提示信息。

     

    1. [MBProgressHUD showHUDAddedTo:self.view animated:YES];  
    2. dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{  
    3.     // Do something...  
    4.     dispatch_async(dispatch_get_main_queue(), ^{  
    5.         [MBProgressHUD hideHUDForView:self.view animated:YES];  
    6.     });  
    7. });  

     

    在这个类库中,提供了丰富的设置方法,可以构建出令人满意的提示框,在github下载这个项目就包括了一个demo,里面涵盖了所以基本的设置方法。

    下面简单的记录一下。

    //新建一个HUD添加到视图中

    MBProgressHUD *HUD;

    HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
    [self.navigationController.view addSubview:HUD];

    // Regiser for HUD callbacks so we can remove it from the window at the right time设置代理
    HUD.delegate = self;

    // Show the HUD while the provided method executes in a new thread 显示HUD的同时执行其他的操作
    [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];

    //设置相关的文本提示信息

    HUD.labelText = @"Loading";

    HUD.detailsLabelText = @"updating data";

    //设置HUD的颜色  Set the hud to display with a color

    HUD.color = [UIColor colorWithRed:0.23 green:0.50 blue:0.82 alpha:0.90];

    // Set determinate mode
    HUD.mode = MBProgressHUDModeDeterminate;

    //HUD的mode包括以下几种:

    typedef enum {
    /** Progress is shown using an UIActivityIndicatorView. This is the default. */  (默认是UIActivityIndicatorView样式
    MBProgressHUDModeIndeterminate,
         
    /**Progress is shown using a round, pie-chart like, progress view. */  (类似饼状图)
    MBProgressHUDModeDeterminate,
    /**Progress is shown using a ring-shaped progress view. */  (类似圆环)
    MBProgressHUDModeAnnularDeterminate,
    /**Shows a custom view */  (自定义)
    MBProgressHUDModeCustomView,
    /** Shows only labels */  (纯文本)
    MBProgressHUDModeText
    } MBProgressHUDMode;

    当mode选择custom时,需要设置custom view

    HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] ;

    使用Blocks

    [hud showAnimated:YES whileExecutingBlock:^{
    [self myTask]; //hud显示过程中执行的其他操作
    } completionBlock:^{
    [hud removeFromSuperview];  
    }];

    // 设置HUD显示所在的视图背景暗淡

    HUD.dimBackground = YES;

    //设置HUD的进度

    HUD.progress

    //其他

    - (void)show:(BOOL)animated;

    - (void)hide:(BOOL)animated;

    - (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay;

  • 相关阅读:
    QT代理Delegates使用实例(三种代理控件)
    delphi中的各种文件类型介绍
    猎豹傅盛:老大老二打仗老三就没了 不要边缘化
    老调重弹,大学有没有意义(没有利用好时间,读什么都没有用)
    应聘linux/ARM嵌入式开发岗位
    气死人不偿命,Q_OBJECT导致的C++报错,而且还看不明白(#ifdef没控制好,导致什么都不认识了)
    坚果云创业团队访谈:我们 DIY 云存储(不要过度关注竞争对手,尤其当我们还是小公司的时候)
    中国版dropbox“坚果云”和它背后的团队故事(大的优势就在于他为用户提供了设定多个文件夹的权利)
    一个灵巧的Delphi多播实事件现方案
    雷军的B面:那些赔到血本无归的失败投资案例
  • 原文地址:https://www.cnblogs.com/yulang314/p/3551312.html
Copyright © 2011-2022 走看看