ios MBProgressHUD使用以及自定义样式

使用第三方的工具类 MBProgressHUD


实现方式如下:

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];

 hud.mode = MBProgressHUDModeAnnularDeterminate;

 hud.labelText = @"正在加载中。。。";


实现自定义视图的提示

#pragma  mark - 添加提示框
-(void)addHud:(NSString *)text :(UIImage *)img{
    
    MBProgressHUD *  HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    HUD.mode = MBProgressHUDModeCustomView;//自定义视图模式
    
    UIImage *image = [img imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate];//可以选择不同方式加载图片
    HUD.customView = [[UIImageView alloc] initWithImage:image];
    HUD.square = YES;//不知道干嘛用的

    HUD.labelText =text;
    [HUD showAnimated:YES whileExecutingBlock:^{
        sleep(1);
    } completionBlock:^{
        [HUD removeFromSuperview];
        
    }];
    

}


一个项目中可能要在多个页面使用,将方法提出来,写成一个公共方法

扩展mbprogresshub

在.h中
#import "MBProgressHUD.h"

@interface MBProgressHUD(Add)

+(void)showErrorWithImg:(NSString *)error :(UIImage *)img toView:(UIView *)view;

+(void)showSucessWithImg:(NSString *)sucess :(UIImage *)img toView:(UIView *)view;

@end

在.m中
#import "HubTipShow.h"
#import "MBProgressHUD.h"

@implementation MBProgressHUD(Add)

+(void)showErrorWithImg:(NSString *)error :(UIImage *)img toView:(UIView *)view{
    MBProgressHUD *  HUD = [MBProgressHUD showHUDAddedTo:view animated:YES];
    HUD.mode = MBProgressHUDModeCustomView;
    
    UIImage *image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    HUD.customView = [[UIImageView alloc] initWithImage:image];
    HUD.square = YES;
    
    HUD.labelText = error;
    [HUD showAnimated:YES whileExecutingBlock:^{
        sleep(1);
    } completionBlock:^{
        [HUD removeFromSuperview];
        
    }];
    
}

+(void)showSucessWithImg:(NSString *)sucess :(UIImage *)img toView:(UIView *)view{
    MBProgressHUD *  HUD = [MBProgressHUD showHUDAddedTo:view animated:YES];
    HUD.mode = MBProgressHUDModeCustomView;
    
    UIImage *image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    HUD.customView = [[UIImageView alloc] initWithImage:image];
    HUD.square = YES;
    
    HUD.labelText = sucess;
    [HUD showAnimated:YES whileExecutingBlock:^{
        sleep(1);
    } completionBlock:^{
        [HUD removeFromSuperview];
        
    }];
}

@end

在controller中,一句话即可解决

        [MBProgressHUD showErrorWithImg:@"账号不能为空" :[UIImage imageNamed:@"errormark"] toView:self.view];
        [MBProgressHUD showSucessWithImg:@“登录成功”:[UIImage imageNamed:@"Checkmark"] toView:self.view];



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值