MBProgressHUD

MBProgressHUD使用简介

GitHub下载地址:https://github.com/jdg/MBProgressHUD

提示框模式有很多种,可以根据需要选取模式使用。

1.工具类中统一提供调用提示框方法

//HUD
+(void)showHUDInView:(UIView*)superView HudType:(MBProgressHUDMode)hudType withText:(NSString*)lableText
{
    if(hudType == MBProgressHUDModeDeterminateHorizontalBar)
        return;

    UIWindow *mainWindow= [[UIApplication sharedApplication] keyWindow];
    for(UIView *view in mainWindow.subviews){
        if ([view isKindOfClass:[MBProgressHUD class]])
        {
            [view removeFromSuperview];
        }
    }
    
    MBProgressHUD*HUD=[[MBProgressHUD alloc] initWithView:superView];
    [superView addSubview:HUD];
    
    switch (hudType) {
        case MBProgressHUDModeIndeterminate:
            //带activeView的 不断转动
        {
             HUD.color = RGBACOLOR(113, 113, 113, 0.8);
             HUD.mode = MBProgressHUDModeIndeterminate;
             HUD.labelText = lableText;
             [HUD show:YES];
        }
            break;
        case MBProgressHUDModeDeterminate:
            //设置模式为进度框形的
        {
            HUD.mode=MBProgressHUDModeDeterminate;
            HUD.labelText=lableText;
            [HUD showAnimated:YES whileExecutingBlock:^{
                float progress = 0.0f;
                while (progress < 1.0f) {
                    progress += 0.01f;
                    HUD.progress = progress;
                    usleep(30000);
                }
            } completionBlock:^{
            }];
        }
            break;
        case MBProgressHUDModeAnnularDeterminate:
            //进度框模式2
        {
            HUD.mode=MBProgressHUDModeAnnularDeterminate;
            HUD.labelText=lableText;
            [HUD showAnimated:YES whileExecutingBlock:^{
                float progress = 0.0f;
                while (progress < 1.0f) {
                    progress += 0.01f;  
                    HUD.progress = progress;
                    usleep(30000);
                }
            } completionBlock:^{
                
            }];
        }
            break;
        case MBProgressHUDModeCustomView:
            //自定义类型 3秒消失
        {
            HUD.mode = MBProgressHUDModeCustomView;
            HUD.labelText=lableText;
            HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image_cs"]];
            HUD.color = RGBACOLOR(113, 113, 113, 0.8);
            [HUD showAnimated:NO whileExecutingBlock:^{
                sleep(3);
            } completionBlock:^{
                [HUD removeFromSuperview];
            }];
        }
            break;
        case MBProgressHUDModeText:
            //纯文本
        {
            HUD.mode = MBProgressHUDModeText;
            HUD.labelText=lableText;
            [HUD showAnimated:YES whileExecutingBlock:^{
                sleep(2);
            } completionBlock:^{
                
            }];
        }
            break;
        case MBProgressHUDModeTransparent:
        {
            HUD.mode = MBProgressHUDModeTransparent;
            HUD.labelText = lableText;
            [HUD show:YES];
        }
            break;
        default:
            break;
    }
}

2.页面自定义方法


/**
 无网络提示
 */
- (void)showNoNetWorkTips
{
    //无网络提示
    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.labelText = @"您的网络好像有问题~";
    HUD.mode = MBProgressHUDModeText;
    
    [HUD showAnimated:YES whileExecutingBlock:^
    {
        sleep(2);
    }
      completionBlock:^
    {
        
    }];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,523评论 25 708
  • 源码来源:gitHub源码 转载于: CocoaChina 来源:南峰子的技术博客 版本:0.9.1 MBPr...
    李小六_阅读 6,466评论 2 5
  • 试过睡着了很快就醒来(12点多),可是没试过这样子睡不着的。 因为熬夜过了睡的点,心跳扑通扑通的。之前连续好多晚都...
    蒋羽燃阅读 336评论 0 0
  • 文||古道西风 清雅 把黄昏远望的惆怅 嵌在字间 把午夜梦醒的渴望 印在笺上 一阕新词 从千里之外款款而来 带着...
    清雅怡然阅读 240评论 0 1
  • 王安石有《纸暖阁》诗:“楚谷越藤真自称,每糊因得减书囊。”说的是他用写过字的楚地谷皮纸和吴越藤纸糊窗子的事情。这种...
    秋雨山茶阅读 609评论 0 0