创建SVProgressHUD的category文件
SVProgressHUD+JR.h
//
// SVProgressHUD+JR.h
// billiards
//
#import <SVProgressHUD/SVProgressHUD.h>
NS_ASSUME_NONNULL_BEGIN
typedef void(^__nullable completeAction)(void);
@interface SVProgressHUD (JR)
/*
纯文字提示
*/
+ (void)showMessage:(nonnull NSString *)message;
/*
加载中+文字提示(文字可为空)
*/
+ (void)showLoadingWithMessage:(nullable NSString *)message;
/*
展示成功+文字提示
*/
+ (void)showSuccessWithMessage:(nullable NSString *)message;
/*
展示失败+文字提示
*/
+ (void)showErrorWithMessage:(nullable NSString *)message;
/*
展示警告+文字提示
*/
+ (void)showWarnWithMessage:(nullable NSString *)message;
/*
自定义图片+文字提示
*/
+ (void)showIcon:(NSString *)iconName WithMessage:(nonnull NSString *)message;
/*
自定义GIF图+文字提示 默认文字:正在加载...
*/
+ (void)showLoadingGif;
/*
自定义GIF图+文字提示
*/
+ (void)showLoadingGifWithMessage:(nonnull NSString *)message;
/*
进度条
*/
//+ (void)showProgress:(float)progress;
/*
隐藏hud
*/
+ (void)hideLoadingHUD;
@end
NS_ASSUME_NONNULL_END
SVProgressHUD+JR.m
//
// SVProgressHUD+JR.m
// billiards
//
#import "SVProgressHUD+JR.h"
// 统一的显示时长
#define showTime 1.5
@implementation SVProgressHUD (JR)
/*
纯文字提示
*/
+ (void)showMessage:(nonnull NSString *)message{
[self hideHUD];
/**
* 设置HUD背景图层的样式:setDefaultMaskType
*
* SVProgressHUDMaskTypeNone:默认图层样式,当HUD显示的时候,允许用户交互。
*
* SVProgressHUDMaskTypeClear:当HUD显示的时候,不允许用户交互。
*
* SVProgressHUDMaskTypeBlack:当HUD显示的时候,不允许用户交互,且显示黑色背景图层。
*
* SVProgressHUDMaskTypeGradient:当HUD显示的时候,不允许用户交互,且显示渐变的背景图层。
*
* SVProgressHUDMaskTypeCustom:当HUD显示的时候,不允许用户交互,且显示背景图层自定义的颜色。
*/
//设置样式 setDefaultStyle
/*
SVProgressHUDStyleLight, // default style, white HUD with black text, HUD background will be blurred
SVProgressHUDStyleDark, // black HUD and white text, HUD background will be blurred
SVProgressHUDStyleCustom // uses the fore- and background color properties
*/
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
[SVProgressHUD setCornerRadius:5];
[SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
[SVProgressHUD showImage:[UIImage imageNamed:@""] status:message];
[SVProgressHUD dismissWithDelay:showTime];
}
/*
加载中+文字提示(文字可为空)
*/
+ (void)showLoadingWithMessage:(nullable NSString *)message
{
// 如果当前视图还有其他提示框,就dismiss
[self hideHUD];
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
[SVProgressHUD setCornerRadius:5];
[SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
// 加载中的提示框一般不要不自动dismiss,比如在网络请求,要在网络请求成功后调用 hideLoadingHUD 方法即可
NSString *str = message != nil ? message : @"正在加载...";
[SVProgressHUD showWithStatus:str];
}
/*
展示成功+文字提示(文字可为空)
*/
+ (void)showSuccessWithMessage:(nullable NSString *)message
{
// 如果当前视图还有其他提示框,就dismiss
[self hideHUD];
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
[SVProgressHUD setCornerRadius:5];
[SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
//加载中的提示框一般不要不自动dismiss,比如在网络请求,要在网络请求成功后调用 hideLoadingHUD 方法即可
NSString *str = message != nil ? message : @"操作成功";
[SVProgressHUD showSuccessWithStatus:str];
[SVProgressHUD dismissWithDelay:showTime];
}
/*
展示失败+文字提示
*/
+ (void)showErrorWithMessage:(nullable NSString *)message
{
// 如果当前视图还有其他提示框,就dismiss
[self hideHUD];
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
[SVProgressHUD setCornerRadius:5];
[SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
//加载中的提示框一般不要不自动dismiss,比如在网络请求,要在网络请求成功后调用 hideLoadingHUD 方法即可
NSString *str = message != nil ? message : @"操作失败";
[SVProgressHUD showErrorWithStatus:str];
[SVProgressHUD dismissWithDelay:showTime];
}
/*
展示警告+文字提示
*/
+ (void)showWarnWithMessage:(nullable NSString *)message
{
[self hideHUD];
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
[SVProgressHUD setCornerRadius:5];
[SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
//加载中的提示框一般不要不自动dismiss,比如在网络请求,要在网络请求成功后调用 hideLoadingHUD 方法即可
if (message) {
[SVProgressHUD showInfoWithStatus:message];
}else{
[SVProgressHUD show];
}
[SVProgressHUD dismissWithDelay:showTime];
}
/*
自定义图片+文字提示
*/
+ (void)showIcon:(NSString *)iconName WithMessage:(nonnull NSString *)message
{
[self hideHUD];
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
[SVProgressHUD setCornerRadius:5];
[SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
[SVProgressHUD showImage:[UIImage imageNamed:iconName] status:message];
[SVProgressHUD dismissWithDelay:showTime];
}
/*
自定义GIF图+文字提示 默认文字:正在加载...
*/
+ (void)showLoadingGif{
[self hideHUD];
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleLight];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
[SVProgressHUD setBackgroundColor:[UIColor clearColor]];
[SVProgressHUD setMinimumDismissTimeInterval:CGFLOAT_MAX];
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"loading" ofType:@"gif"]];
[SVProgressHUD setInfoImage:[UIImage sd_imageWithGIFData:data]];
[SVProgressHUD setImageViewSize:CGSizeMake(60, 60)];
[SVProgressHUD showInfoWithStatus:@"加载中..."];
[SVProgressHUD setForegroundColor:[UIColor darkGrayColor]];//设置文字颜色
}
/*
自定义GIF图+文字提示
*/
+ (void)showLoadingGifWithMessage:(nonnull NSString *)message{
[self hideHUD];
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleLight];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
[SVProgressHUD setBackgroundColor:[UIColor clearColor]];
[SVProgressHUD setMinimumDismissTimeInterval:CGFLOAT_MAX];
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"loading" ofType:@"gif"]];
[SVProgressHUD setInfoImage:[UIImage sd_imageWithGIFData:data]];
[SVProgressHUD setImageViewSize:CGSizeMake(60, 60)];
NSString *str = message != nil ? message : @"正在加载...";
[SVProgressHUD showInfoWithStatus:str];
[SVProgressHUD setForegroundColor:[UIColor darkGrayColor]];
}
///*
// 进度条
// */
//+ (void)showProgress:(float)progress {
// [self hideHUD];
// [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
// [SVProgressHUD setCornerRadius:5];
// [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
// [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
// [SVProgressHUD showProgress:progress];
//}
/*
隐藏hud
*/
+ (void)hideHUD{
[SVProgressHUD dismiss];
}
@end
网友评论