MBProgressHUD 提示很好用的 就是重复的多 网上找了一些大神们的封装 自己加一些自已需要的 以后备用

.h 文件

#import <Foundation/Foundation.h>

#import <MBProgressHUD/MBProgressHUD.h>

NS_ASSUME_NONNULL_BEGIN

 

typedef NS_ENUM(NSInteger, SJZProgessMode) {

    SJZProgessModeOnlyText = 0,              //文字

    SJZProgessModeLoading = 1,               //加载菊花

    SJZProgessModeCircle = 2,                //加载环形

    SJZProgessModeCircleLoading = 3,         //加载圆形-要处理进度值

    SJZProgessModeCustomAnimation = 4,       //自定义加载动画(序列帧实现)

    SJZProgessModeSuccess = 5,               //成功

    SJZProgessModeCustomerImage = 6          //自定义图片

    

};

 

@interface SJZProgessHUD : NSObject

 

/** ================= 属性 ============*/

 

@property (nonatomic ,strong) MBProgressHUD *hud;

 

/** ========== 方法 ==================*/

 

+(instancetype)shareinstance;

 

//显示

+(void)show:(NSString *)msg inView:(UIView *)view mode:(SJZProgessMode *)Mode;

 

//显示提示(1秒后消失)

+(void)showMessage:(NSString *)msg inView:(UIView *)view;

 

//显示提示(N秒后消失)

+(void)showMessage:(NSString *)msg inView:(UIView *)view afterDelayTime:(NSInteger)delay;

 

//在最上层显示 - 不需要指定showview

+(void)showMsgWithoutView:(NSString *)msg;

 

//显示进度(菊花)

+(void)showProgress:(NSString *)msg inView:(UIView *)view;

 

//显示进度(环形)

+(void)showProgressCircleNoValue:(NSString *)msg inView:(UIView *)view ;

 

//显示进度(转圈-要处理数据加载进度)

+(MBProgressHUD *)showProgressCircle:(NSString *)msg inView:(UIView *)view;

 

//显示成功提示

+(void)showSuccess:(NSString *)msg inview:(UIView *)view;

 

//显示提示、带静态图片,比如失败,用失败图片即可,警告用警告图片等

+(void)showMsgWithImage:(NSString *)msg imageName:(NSString *)imageName inview:(UIView *)view;

 

//显示自定义动画(自定义动画序列帧  找UI做就可以了)

+(void)showCustomAnimation:(NSString *)msg withImgArry:(NSArray *)imgArry inview:(UIView *)view;

 

//隐藏

+(void)hide;

 

@end

 

.m 文件

#import "SJZProgessHUD.h"

 

@implementation SJZProgessHUD

 

+(instancetype)shareinstance{

    

    static SJZProgessHUD *instance = nil;

    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{

        instance = [[SJZProgessHUD alloc] init];

    });

    

    return instance;

    

}

 

+(void)show:(NSString *)msg inView:(UIView *)view mode:(SJZProgessMode *)Mode{

    [self show:msg inView:view mode:Mode customImgView:nil];

}

 

+(void)show:(NSString *)msg inView:(UIView *)view mode:(SJZProgessMode *)Mode customImgView:(UIImageView *)customImgView{

    //如果已有弹框,先消失

    if ([SJZProgessHUD shareinstance].hud != nil) {

        [[SJZProgessHUD shareinstance].hud hideAnimated:YES];

        [SJZProgessHUD shareinstance].hud = nil;

    }

    

    //4\4s屏幕避免键盘存在时遮挡

    if ([UIScreen mainScreen].bounds.size.height == 480) {

        [view endEditing:YES];

    }

    

    [SJZProgessHUD shareinstance].hud = [MBProgressHUD showHUDAddedTo:view animated:YES];

        

    //是否设置黑色背景,这两句配合使用

    [SJZProgessHUD shareinstance].hud.bezelView.backgroundColor = [UIColor blackColor];

    [SJZProgessHUD shareinstance].hud.bezelView.color = [UIColor blackColor];

    [SJZProgessHUD shareinstance].hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;

    [SJZProgessHUD shareinstance].hud.contentColor = [UIColor whiteColor];

    

    [[SJZProgessHUD shareinstance].hud setMargin:10];

    [[SJZProgessHUD shareinstance].hud setRemoveFromSuperViewOnHide:YES];

    [SJZProgessHUD shareinstance].hud.detailsLabel.text = msg;

 

    [SJZProgessHUD shareinstance].hud.detailsLabel.font = [UIFont systemFontOfSize:14];

    switch ((NSInteger)Mode) {

        case SJZProgessModeOnlyText:

            [SJZProgessHUD shareinstance].hud.mode = MBProgressHUDModeText;

            break;

 

        case SJZProgessModeLoading:

            [SJZProgessHUD shareinstance].hud.mode = MBProgressHUDModeIndeterminate;

            break;

 

        case SJZProgessModeCircle:{

            [SJZProgessHUD shareinstance].hud.mode = MBProgressHUDModeCustomView;

            UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"loading"]];

            CABasicAnimation *animation= [CABasicAnimation animationWithKeyPath:@"transform.rotation"];

            animation.toValue = [NSNumber numberWithFloat:M_PI*2];

            animation.duration = 1.0;

            animation.repeatCount = 100;

            [img.layer addAnimation:animation forKey:nil];

            [SJZProgessHUD shareinstance].hud.customView = img;

            

            

            break;

        }

        case SJZProgessModeCustomerImage:

            [SJZProgessHUD shareinstance].hud.mode = MBProgressHUDModeCustomView;

            [SJZProgessHUD shareinstance].hud.customView = customImgView;

            break;

 

        case SJZProgessModeCustomAnimation:

            //这里设置动画的背景色

            [SJZProgessHUD shareinstance].hud.bezelView.color = [UIColor yellowColor];

 

            [SJZProgessHUD shareinstance].hud.mode = MBProgressHUDModeCustomView;

            [SJZProgessHUD shareinstance].hud.customView = customImgView;

            

            break;

 

        case SJZProgessModeSuccess:

            [SJZProgessHUD shareinstance].hud.mode = MBProgressHUDModeCustomView;

            [SJZProgessHUD shareinstance].hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"success"]];

            break;

 

        default:

            break;

    }

    

    

    

}

    

 

+(void)hide{

    if ([SJZProgessHUD shareinstance].hud != nil) {

        [[SJZProgessHUD shareinstance].hud hideAnimated:YES];

    }

}

 

 

+(void)showMessage:(NSString *)msg inView:(UIView *)view{

    [self show:msg inView:view mode:SJZProgessModeOnlyText];

    [[SJZProgessHUD shareinstance].hud hideAnimated:YES afterDelay:1.0];

}

 

 

 

+(void)showMessage:(NSString *)msg inView:(UIView *)view afterDelayTime:(NSInteger)delay{

    [self show:msg inView:view mode:SJZProgessModeOnlyText];

    [[SJZProgessHUD shareinstance].hud hideAnimated:YES afterDelay:delay];

}

 

+(void)showSuccess:(NSString *)msg inview:(UIView *)view{

    [self show:msg inView:view mode:SJZProgessModeSuccess];

    [[SJZProgessHUD shareinstance].hud hideAnimated:YES afterDelay:1.0];

    

}

 

+(void)showMsgWithImage:(NSString *)msg imageName:(NSString *)imageName inview:(UIView *)view{

    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];

    [self show:msg inView:view mode:SJZProgessModeCustomerImage customImgView:img];

    [[SJZProgessHUD shareinstance].hud hideAnimated:YES afterDelay:1.0];

}

 

 

+(void)showProgress:(NSString *)msg inView:(UIView *)view{

    [self show:msg inView:view mode:SJZProgessModeLoading];

}

 

+(MBProgressHUD *)showProgressCircle:(NSString *)msg inView:(UIView *)view{

    if (view == nil) view = (UIView*)[UIApplication sharedApplication].delegate.window;

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

    hud.mode = MBProgressHUDModeAnnularDeterminate;

    hud.detailsLabel.text = msg;

    return hud;

    

    

}

 

+(void)showProgressCircleNoValue:(NSString *)msg inView:(UIView *)view{

    [self show:msg inView:view mode:SJZProgessModeCircle];

    

}

 

 

+(void)showMsgWithoutView:(NSString *)msg{

    UIWindow *view = [[UIApplication sharedApplication].windows lastObject];

    [self show:msg inView:view mode:SJZProgessModeOnlyText];

    [[SJZProgessHUD shareinstance].hud hideAnimated:YES afterDelay:1.0];

    

}

 

+ (void)showCustomAnimation:(NSString *)msg withImgArry:(NSArray *)imgArry inview:(UIView *)view{

    

    UIImageView *showImageView = [[UIImageView alloc] init];

    showImageView.animationImages = imgArry;

    [showImageView setAnimationRepeatCount:0];

    [showImageView setAnimationDuration:(imgArry.count + 1) * 0.075];

    [showImageView startAnimating];

    

    [self show:msg inView:view mode:SJZProgessModeCustomAnimation customImgView:showImageView];

    

 

}

 

@end