iOS第三方 - SVProgressHUD

SVProgressHUD

1 - SVProgressHUD 是一个弹出提示层,用来提示网络加载或提示对错,多用于程序正在执行耗时较长的任务,需要用户等待。它和 MBProgressHUD 效果差不多,不过它不需要使用协议,同时也不需要声明实例,直接通过类方法进行调用

2 - 第三方框架中关于 HUD 有 MBProgressHUD 和 SVProgressHUD,其实会一种就可以,建议选择后者

3 - SVProgressHUD 适用于 ARC 环境,在 MRC 中 TARGETS / Build Phases / Compile Sources,将 items 的 Compiler Flags 修改为 -fobjc-arc 

HUD 常用 API

1 - 方法说明

复制代码
 1 + (void)show;// 显示:状态是一个迅速转动的圈
 2 + (void)showWithMaskType:(SVProgressHUDMaskType)maskType;// 显示并且带着一个状态
 3 
 4 + (void)showWithStatus:(NSString*)status;// 显示并且带着文字
 5 + (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
 6 
 7 + (void)showProgress:(float)progress;    // 显示进度:状态是一个进度圈
 8 + (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType;
 9 + (void)showProgress:(float)progress status:(NSString*)status;
10 + (void)showProgress:(float)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
11 
12 + (void)showInfoWithStatus:(NSString *)string;  // 显示消息信息
13 + (void)showInfoWithStatus:(NSString *)string maskType:(SVProgressHUDMaskType)maskType;
14 
15 + (void)showSuccessWithStatus:(NSString*)string;//显示成功消息
16 + (void)showSuccessWithStatus:(NSString*)string maskType:(SVProgressHUDMaskType)maskType;
17 
18 + (void)showErrorWithStatus:(NSString *)string; //显示错误消息
19 + (void)showErrorWithStatus:(NSString *)string maskType:(SVProgressHUDMaskType)maskType;
20 
21 + (void)showImage:(UIImage*)image status:(NSString*)status;// 显示自己设置的图片:图片尺寸:28 * 28 px
22 + (void)showImage:(UIImage*)image status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
23 
24 + (void)setStatus:(NSString*)string;         // 改变显示着的HUD的文字
25 + (void)setOffsetFromCenter:(UIOffset)offset;// 距离中心点的偏移量
26 + (void)resetOffsetFromCenter;   // 返回中心点
27 + (void)popActivity;             // 消除一个HUD:progress == 0时,执行dismiss方法
28 + (void)dismiss;   // 消失
29 + (BOOL)isVisible; // 是否正在显示
复制代码

2 - 属性配置

复制代码
 1 + (void)setBackgroundColor:(UIColor*)color;// 背景颜色:默认是白色
 2 + (void)setForegroundColor:(UIColor*)color;// progress 和 label颜色:默认黑色
 3 + (void)setRingThickness:(CGFloat)width;   // progress 宽度
 4 + (void)setFont:(UIFont*)font;// 字体
 5 + (void)setInfoImage:(UIImage*)image;   // 消息的图片
 6 + (void)setSuccessImage:(UIImage*)image;// 成功时的图片
 7 + (void)setErrorImage:(UIImage*)image;  // 失败时的图片
 8 + (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType;// 当HUD显示时,用户是否可以点击其他控件
 9 /**
10  
11  SVProgressHUDMaskTypeNone      // 允许用户进行其他用户操作
12  SVProgressHUDMaskTypeClear     // 不允许用户进行其他用户操作
13  SVProgressHUDMaskTypeBlack,    // 不允许用户进行其他用户操作,并且背景是黑色的
14  SVProgressHUDMaskTypeGradient  // 允许用户进行其他用户操作,并且背景是渐变的黑色
15  
16 */
17 + (void)setViewForExtension:(UIView*)view;// 延展一个图片,必须设置#define SV_APP_EXTENSIONS
复制代码

3 - 通知:在通知中 userInfo 字典中存储了 HUD 的状态,其 key 值是 SVProgressHUDStatusUserInfoKey

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

4 - 代码示例:布局四个 Button 按钮,分别触发不同 SVProgressHUD 的效果

复制代码
 1 // 按钮01
 2 - (IBAction)bt01:(id)sender {
 3 
 4     [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeClear];
 5     [self performSelector:@selector(dismiss) withObject:nil afterDelay:5];
 6 }
 7 
 8 // 按钮02
 9 - (IBAction)bt02:(id)sender {
10 
11     [SVProgressHUD showWithStatus:@"加载中..." maskType:SVProgressHUDMaskTypeGradient];
12     [self performSelector:@selector(dismiss) withObject:nil afterDelay:5];
13 }
14 
15 // 按钮03
16 - (IBAction)bt03:(id)sender {
17 
18     [SVProgressHUD showProgress:0.0 status:@"3秒后开始加载,请稍候..." maskType:SVProgressHUDMaskTypeGradient];
19     [self performSelector:@selector(rateOfProgress) withObject:nil afterDelay:3];
20 }
21 
22 // 按钮04
23 - (IBAction)bt04:(id)sender {
24 
25     [SVProgressHUD showSuccessWithStatus:@"success" maskType:SVProgressHUDMaskTypeGradient];27 }
26 
27 // 消失
28 -(void)dismiss{
29 
30     [SVProgressHUD dismiss];
31 }
32 
33 // 实现进度功能
34 // 模拟数据
35 static float progressValue = 0.0;
36 -(void)rateOfProgress{
37 
38     progressValue += 0.1;
39 
40     [SVProgressHUD showProgress:progressValue status:@"加载中..."];// showProgress: 的参数float默认范围 0 ~ 1
41     if (progressValue <= 1) {
42 
43         [self performSelector:@selector(rateOfProgress) withObject:nil afterDelay:0.25];
44     }else{
45 
46         [self performSelector:@selector(dismiss) withObject:nil afterDelay:0];
47     }
48 }
复制代码

运行效果:Btn1  |  Btn2  |  Btn3

       Btn4  |  下载进度...

                       

         

链接:SVProgressHUD

https://pan.baidu.com/s/16ifoRHr6cYDNqN7OhXP_5Q

aolg

posted on   低头捡石頭  阅读(279)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示