测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可 | 自定义 |
发布最后发布 | 2016年6月 |
由 bestkai 维护。
依赖 | |
YYWebImage | >= 0 |
YYText | >= 0 |
SVProgressHUD | >= 0 |
SVProgressHUD
是一个干净、易于使用的 HUD,旨在在 iOS 和 tvOS 上显示正在进行的任务进度。
在 Appetize.io 上尝试 SVProgressHUD
。
SVProgressHUD/SVProgressHUD
文件夹拖入您的项目中。SVProgressHUD.bundle
已经添加到 Targets -> Build Phases -> Copy Bundle Resources
。(在 /Demo
中的示例 Xcode 项目中查看)
SVProgressHUD
是作为 单例 创建的(即不需要显式分配和实例化;您可以直接调用 [SVProgressHUD method]
)。
明智地使用 SVProgressHUD
!只有在您绝对需要执行一个任务将用户向前推进时再使用它。不良的使用案例:下拉刷新、无限滚动、发送消息。
在您的应用程序中使用 SVProgressHUD
通常看起来像这样(使用 Grand Central Dispatch)
[SVProgressHUD show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// time-consuming task
dispatch_async(dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
});
});
您可以使用以下之一显示不确定任务的进度状态
+ (void)show;
+ (void)showWithStatus:(NSString*)string;
如果您想让 HUD 反映任务的进度,请使用以下之一
+ (void)showProgress:(CGFloat)progress;
+ (void)showProgress:(CGFloat)progress status:(NSString*)status;
可以使用以下方式隐藏 HUD
+ (void)dismiss;
+ (void)dismissWithDelay:(NSTimeInterval)delay;
如果您想堆叠 HUD,可以使用
+ (void)popActivity;
一旦 popActivity
调用与显示调用的数量相匹配,HUD 将会消失。
或者在稍后消失前显示一个确认图标。显示时间取决于 minimumDismissTimeInterval
和给定字符串的长度。
+ (void)showInfoWithStatus:(NSString*)string;
+ (void)showSuccessWithStatus:(NSString*)string;
+ (void)showErrorWithStatus:(NSString*)string;
+ (void)showImage:(UIImage*)image status:(NSString*)string;
SVProgressHUD
可以通过以下方法进行自定义
+ (void)setDefaultStyle:(SVProgressHUDStyle)style; // default is SVProgressHUDStyleLight
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; // default is SVProgressHUDMaskTypeNone
+ (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type; // default is SVProgressHUDAnimationTypeFlat
+ (void)setMinimumSize:(CGSize)minimumSize; // default is CGSizeZero, can be used to avoid resizing for a larger message
+ (void)setRingThickness:(CGFloat)width; // default is 2 pt
+ (void)setRingRadius:(CGFloat)radius; // default is 18 pt
+ (void)setRingNoTextRadius:(CGFloat)radius; // default is 24 pt
+ (void)setCornerRadius:(CGFloat)cornerRadius; // default is 14 pt
+ (void)setFont:(UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
+ (void)setForegroundColor:(UIColor*)color; // default is [UIColor blackColor], only used for SVProgressHUDStyleCustom
+ (void)setBackgroundColor:(UIColor*)color; // default is [UIColor whiteColor], only used for SVProgressHUDStyleCustom
+ (void)setBackgroundLayerColor:(UIColor*)color; // default is [UIColor colorWithWhite:0 alpha:0.4], only used for SVProgressHUDMaskTypeCustom
+ (void)setInfoImage:(UIImage*)image; // default is the bundled info image provided by Freepik
+ (void)setSuccessImage:(UIImage*)image; // default is bundled success image from Freepik
+ (void)setErrorImage:(UIImage*)image; // default is bundled error image from Freepik
+ (void)setViewForExtension:(UIView*)view; // default is nil, only used if #define SV_APP_EXTENSIONS is set
+ (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval; // default is 5.0 seconds
+ (void)setFadeInAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
+ (void)setFadeOutAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
此外,SVProgressHUD
支持 UIAppearance
协议的大多数上述方法。
根据标准,SVProgressHUD
提供了两种预配置样式
SVProgressHUDStyleLight
:白色背景,带黑色加载指示器和文字SVProgressHUDStyleDark
:黑色背景,带白色加载指示器和文字如果你想要使用自定义颜色,结合setForegroundColor
和setBackgroundColor:
,不要忘记通过setDefaultStyle:
设置为SVProgressHUDStyleCustom
。
SVProgressHUD
通过NSNotificationCenter
发布四个通知,以响应其展示/消失
SVProgressHUDWillAppearNotification
:当展示动画开始时SVProgressHUDDidAppearNotification
:当展示动画完成时SVProgressHUDWillDisappearNotification
:当消失动画开始时SVProgressHUDDidDisappearNotification
:当消失动画完成时每个通知都会传递一个包含 HUD 的状态字符串(如果有)的 userInfo
字典,可以通过 SVProgressHUDStatusUserInfoKey
获取。
SVProgressHUD
还会在用户触摸整体屏幕时发布 SVProgressHUDDidReceiveTouchEventNotification
,或者在用户直接触摸 HUD 时代发布 SVProgressHUDDidTouchDownInsideNotification
。对于这些通知,不传递 userInfo
,但对象参数包含相关的 UIEvent
。
当在应用扩展中使用 SVProgressHUD
时,使用 #define SV_APP_EXTENSIONS
以避免使用不可用的 API。此外,从你的扩展视图控制器调用 setViewForExtension:
,使用 self.view
。
如果你有功能请求或错误报告,请自由地通过发送拉取请求或在新建问题来帮助我们。请花点时间阅读由 Nicolas Gallagher 编写的指南。
SVProgressHUD
在 MIT 许可证 的条款和条件下发布。成功、错误和信息图标由 Freepik 来自 Flaticon 制作,并许可在 Creative Commons BY 3.0 下使用。
SVProgressHUD
由 Sam Vermette、Tobias Tiemerding 和 项目的贡献者 提供。如果你在你的项目中使用了 SVProgressHUD
,我们会非常感激你的署名。