美文网首页
MBProgressHud自定义分类

MBProgressHud自定义分类

作者: YannChee | 来源:发表于2018-08-01 18:09 被阅读9次

记录下来,方便以后复制粘贴

#import <MBProgressHUD/MBProgressHUD.h>

@interface MBProgressHUD (QYExtension)

+ (void)qy_showWithText:(NSString *)text icon:(NSString *)icon toView:(UIView *)view;

+ (void)qy_showProgressView;

+ (void)qy_hideProgressView ;

+ (void)qy_showInfoWithStatus:(NSString *)text;

+ (void)qy_showSuccessWithStatus:(NSString *)text ;

+ (void)qy_showFailureWithStatus:(NSString *)text ;
@end
#import "MBProgressHUD+QYExtension.h"

@implementation MBProgressHUD (QYExtension)

+ (void)qy_showWithText:(NSString *)text icon:(NSString *)icon toView:(UIView *)view {
    if (!text.length && !icon.length) {
        return;
    }
    [MBProgressHUD hideHUDForView:view animated:NO];
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view];
    if (icon) {
        hud.mode = MBProgressHUDModeCustomView;
        hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: icon]];
    } else {
        hud.mode = MBProgressHUDModeText;
    }
    hud.detailsLabel.font = [UIFont systemFontOfSize:15];
    hud.label.text = text;
    [view addSubview:hud];
    [hud showAnimated:YES];
    [hud hideAnimated:YES afterDelay:1.0];
}


+ (void)qy_showProgressView {
    [MBProgressHUD hideHUDForView:[UIApplication sharedApplication].delegate.window animated:NO];
    [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
}

+ (void)qy_hideProgressView {
    [MBProgressHUD hideHUDForView:[UIApplication sharedApplication].delegate.window animated:YES];
}



+ (void)qy_showInfoWithStatus:(NSString *)text {
    [MBProgressHUD qy_showWithText:text icon:nil toView:[UIApplication sharedApplication].delegate.window];
}

+ (void)qy_showSuccessWithStatus:(NSString *)text {
    [MBProgressHUD qy_showWithText:text icon:@"MBProgressHud_success" toView:[UIApplication sharedApplication].delegate.window];
}

+ (void)qy_showFailureWithStatus:(NSString *)text {
    [MBProgressHUD qy_showWithText:text icon:@"MBProgressHud_failure" toView:[UIApplication sharedApplication].delegate.window];
}

@end

相关文章

网友评论

      本文标题:MBProgressHud自定义分类

      本文链接:https://www.haomeiwen.com/subject/ycwrvftx.html