GCMessageKit 0.0.2

GCMessageKit 0.0.2

测试已测试
语言语言 Obj-CObjective C
许可 自定义
发布最后发布2016年6月

bestkai 维护。



 
依赖
YYWebImage>= 0
YYText>= 0
SVProgressHUD>= 0
 

  • 作者
  • BestKai

SVProgressHUD

SVProgressHUD 是一个干净、易于使用的 HUD,旨在在 iOS 和 tvOS 上显示正在进行的任务进度。

SVProgressHUD

演示

Appetize.io 上尝试 SVProgressHUD

安装

手工安装

  • SVProgressHUD/SVProgressHUD 文件夹拖入您的项目中。
  • 请确保 SVProgressHUD.bundle 已经添加到 Targets -> Build Phases -> Copy Bundle Resources
  • QuartzCore 框架添加到您的项目中。

使用方法

(在 /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];
    });
});

显示 HUD

您可以使用以下之一显示不确定任务的进度状态

+ (void)show;
+ (void)showWithStatus:(NSString*)string;

如果您想让 HUD 反映任务的进度,请使用以下之一

+ (void)showProgress:(CGFloat)progress;
+ (void)showProgress:(CGFloat)progress status:(NSString*)status;

隐藏 HUD

可以使用以下方式隐藏 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:黑色背景,带白色加载指示器和文字

如果你想要使用自定义颜色,结合setForegroundColorsetBackgroundColor:,不要忘记通过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 编写的指南。

许可证

SVProgressHUDMIT 许可证 的条款和条件下发布。成功、错误和信息图标由 Freepik 来自 Flaticon 制作,并许可在 Creative Commons BY 3.0 下使用。

鸣谢

SVProgressHUDSam VermetteTobias Tiemerding项目的贡献者 提供。如果你在你的项目中使用了 SVProgressHUD,我们会非常感激你的署名。