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:^
    {
        
    }];
}

你可能感兴趣的:(MBProgressHUD)