[iOS功能]- SVProgressHUD的一些常见用法

2021-03-19  本文已影响0人  AlwaysLuckyMa

SVProgressHUD

GitHub地址:https://github.com/TransitApp/SVProgressHUD

SVProgressHUD和MBProgressHUD效果差不多,特点就是不需要使用协议,同时也不需要声明实例。直接通过类方法就可以调用:
[SVProgressHUD method]
[SVProgressHUD dismiss]

加载环

基本方法

     + (void)show;    显示:状态是一个迅速转动的圈
     + (void)showWithMaskType:(SVProgressHUDMaskType)maskType; 显示并且带着一个状态
     + (void)showWithStatus:(NSString*)status; 显示并且带着文字
     + (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
 
     + (void)showProgress:(float)progress;  //显示进度:状态是一个进度圈
     + (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType;
     + (void)showProgress:(float)progress status:(NSString*)status;
     + (void)showProgress:(float)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
 
     + (void)setStatus:(NSString*)string; // 改变正显示着的HUD的文字
 
     // stops the activity indicator, shows a glyph + status, and dismisses HUD a little bit later
     + (void)showInfoWithStatus:(NSString *)string;   //显示消息信息,其实就是中心图片更换了
     + (void)showInfoWithStatus:(NSString *)string maskType:(SVProgressHUDMaskType)maskType;
 
     + (void)showSuccessWithStatus:(NSString*)string; //显示成功消息
     + (void)showSuccessWithStatus:(NSString*)string maskType:(SVProgressHUDMaskType)maskType;
 
     + (void)showErrorWithStatus:(NSString *)string; //显示错误消息
     + (void)showErrorWithStatus:(NSString *)string maskType:(SVProgressHUDMaskType)maskType;
 
     // use 28x28 white pngs
     + (void)showImage:(UIImage*)image status:(NSString*)status; //显示自己设置的图片,图片大小事28 * 28 px
     + (void)showImage:(UIImage*)image status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
 
     + (void)setOffsetFromCenter:(UIOffset)offset; //距离中心点的偏移量
     + (void)resetOffsetFromCenter; //返回中心点
 
     + (void)popActivity; // 消除一个HUD,根据其实现方法如果前面有执行了好几次show方法,如果给定的progress == 0 或者 pregress < 0那样就会让使一个参数+1,执行这个方法会使那个参数-1,如果参数==0时 执行dismiss方法。
     + (void)dismiss; 消失
 
     + (BOOL)isVisible; 是否正在显示

关于HUD的属性配置

     + (void)setBackgroundColor:(UIColor*)color;       //背景颜色          // default is [UIColor whiteColor]
     + (void)setForegroundColor:(UIColor*)color;       //progress 和 label颜色          // default is [UIColor blackColor]
     + (void)setRingThickness:(CGFloat)width;          //progress 宽度          // default is 4 pt
     + (void)setFont:(UIFont*)font;                     //字体         // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
     + (void)setInfoImage:(UIImage*)image;               //消息的图片        // default is the bundled info image provided by Freepik
     + (void)setSuccessImage:(UIImage*)image;            //成功时的图片        // default is the bundled success image provided by Freepik
     + (void)setErrorImage:(UIImage*)image;              //失败时的图片        // default is the bundled error image provided by Freepik
     + (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; //当HUD显示时,用户是否可以点击其他控件// default is SVProgressHUDMaskTypeNone
 
     SVProgressHUDMaskTypeNone = 1,  // 允许用户进行其他用户操作
     SVProgressHUDMaskTypeClear,     // 不允许用户进行其他用户操作
     SVProgressHUDMaskTypeBlack,     // 不允许用户进行其他用户操作,并且背景是黑色的
     SVProgressHUDMaskTypeGradient   // 允许用户进行其他用户操作,并且背景是渐变的黑色
 
     + (void)setViewForExtension:(UIView*)view;         //可以延展一个图片必须设置#define SV_APP_EXTENSIONS

关于HUD的通知

 extern NSString * const SVProgressHUDDidReceiveTouchEventNotification; //在HUD外点击
 extern NSString * const SVProgressHUDDidTouchDownInsideNotification;   //在HUD中点击
 extern NSString * const SVProgressHUDWillDisappearNotification;        //将要显示
 extern NSString * const SVProgressHUDDidDisappearNotification;         //已经显示
 extern NSString * const SVProgressHUDWillAppearNotification;           //将要消失
 extern NSString * const SVProgressHUDDidAppearNotification;            //已经消失
 extern NSString * const SVProgressHUDStatusUserInfoKey;                //HUD的状态

在通知中userInfo字典中存储了HUD的状态,其key为SVProgressHUDStatusUserInfoKey

整理自:
https://www.jianshu.com/p/5750c72074a7
https://www.jianshu.com/p/1ec4dca92e71

上一篇下一篇

猜你喜欢

热点阅读