[翻译] SVProgressHUD

简介:

SVProgressHUD

https://github.com/TransitApp/SVProgressHUD

 

SVProgressHUD is a clean and easy-to-use HUD meant to display the progress of an ongoing task.

SVProgressHUD 是一个清新易用的指示器,用来指示正在执行的任务。

 

Installation

From CocoaPods CocoaPods安装

I'm not a big fan of CocoaPods, so tend to not keep it updated. If you really want to use SVProgressHUD with CocoaPods, I suggest you use pod 'SVProgressHUD', :head to pull from the master branch directly. I'm usually careful about what I push there and is the version I use myself in all my projects.

Manually 手动安装

  • Drag the SVProgressHUD/SVProgressHUD folder into your project.
  • Add the QuartzCore framework to your project.

Usage 使用

(see sample Xcode project in /Demo)

SVProgressHUD is created as a singleton (i.e. it doesn't need to be explicitly allocated and instantiated; you directly call [SVProgressHUD method]).

SVProgressHUD 是单例模式(也就是说你只需要调用[SVProgressHUD method]即可)

Use SVProgressHUD wisely! Only use it if you absolutely need to perform a task before taking the user forward. Bad use case examples: pull to refresh, infinite scrolling, sending message.

请明智的使用SVProgressHUD!仅仅当你确保绝对要执行一项任务了。以下是不当的使用情形:下拉刷新,发送消息,无限滚动

Using SVProgressHUD in your app will usually look as simple as this (using Grand Central Dispatch):

请以以下的方式使用SVProgressHUD 

[SVProgressHUD show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // time-consuming task dispatch_async(dispatch_get_main_queue(), ^{ [SVProgressHUD dismiss]; }); }); 

Showing the HUD 显示指示器

You can show the status of indeterminate tasks using one of the following:

你可以用以下的方式来指示你在做什么:

+ (void)show; + (void)showWithMaskType:(SVProgressHUDMaskType)maskType; + (void)showWithStatus:(NSString*)string; + (void)showWithStatus:(NSString*)string maskType:(SVProgressHUDMaskType)maskType; 

If you'd like the HUD to reflect the progress of a task, use one of these:

如果你想显示任务的进度情况,用下面的方法:

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

Dismissing the HUD 隐藏指示器

It can be dismissed right away using:

你可以用以下方法隐藏指示器:

+ (void)dismiss; 

If you'd like to stack HUDs, you can balance out every show call using:

如果你想用栈的方式存储按照顺序来显示,你可以依次调用以下方法:

+ (void)popActivity; 

The HUD will get dismissed once the popActivity calls will match the number of show calls.

这个指示器会依照顺序依次消失

Or show a confirmation glyph before before getting dismissed 1 second later using:

或者按照标志位延时1s钟消失:

+ (void)showSuccessWithStatus:(NSString*)string; + (void)showErrorWithStatus:(NSString *)string; + (void)showImage:(UIImage*)image status:(NSString*)string; // use 28x28 pngs 

 

Customization

SVProgressHUD can be customized via the following methods:

SVProgressHUD 可以用以下方式定制:

+ (void)setBackgroundColor:(UIColor*)color; // default is [UIColor whiteColor] + (void)setForegroundColor:(UIColor*)color; // default is [UIColor blackColor] + (void)setRingThickness:(CGFloat)width; // default is 4 pt + (void)setFont:(UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline] + (void)setSuccessImage:(UIImage*)image; // default is bundled success image from Glyphish + (void)setErrorImage:(UIImage*)image; // default is bundled error image from Glyphish 

 

Notifications

SVProgressHUD posts four notifications via NSNotificationCenter in response to being shown/dismissed:

SVProgressHUD 通过通知中心发送4种通知来显示/隐藏:

  • SVProgressHUDWillAppearNotification when the show animation starts
  • SVProgressHUDDidAppearNotification when the show animation completes
  • SVProgressHUDWillDisappearNotification when the dismiss animation starts
  • SVProgressHUDDidDisappearNotification when the dismiss animation completes

Each notification passes a userInfo dictionary holding the HUD's status string (if any), retrievable viaSVProgressHUDStatusUserInfoKey.

每一个通知都传递一个userInfo字典来装载HUD状态值,其值可以通过viaSVProgressHUDStatusUserInfoKey来获取。

SVProgressHUD also posts SVProgressHUDDidReceiveTouchEventNotification when users touch on the screen. For this notification userInfo is not passed but the object parameter contains the UIEvent that related to the touch.

SVProgressHUD当用户触摸屏幕的时候,也能发送SVProgressHUDDidReceiveTouchEventNotification。这种通知方式呢,并没有把userInfo当做参数来传递,取而代之的是object对象,包含了这个触摸的事件。

目录
相关文章
操作系统:中断和异常
内中断(异常):与当前CPU的执行的指令有关,中断信号来自CPU内部 外中断:与当前CPU的执行的指令无关,中断信号来自CPU外部 (注:在大部分教材中,“中断”是狭义的中断,指外中断;而内中断则称为异常)
756 0
|
编解码 算法 搜索推荐
淘宝人生里的虚拟人像渲染技术
全程干货,淘宝人生里的虚拟人像是如何实现的?
淘宝人生里的虚拟人像渲染技术
|
12月前
|
敏捷开发 运维 数据可视化
DevOps看板工具中的协作功能:如何打破开发、测试与运维之间的沟通壁垒
在DevOps实践中,看板工具通过可视化任务管理和自动化流程,提升开发与运维团队的协作效率。它支持敏捷开发、持续交付,助力团队高效应对需求变化,实现跨职能协作与流程优化。
|
Linux 开发工具
如何在 Linux 中编辑配置文件?
如何在 Linux 中编辑配置文件?
903 2
如何在 Linux 中编辑配置文件?
|
云安全 安全 大数据
华为增强版专线卫士高性能真安全,守护甘肃兰投集团网络安全,保障专线体验品质
甘肃移动政企团队协同华为乾坤云安全团队进行现网出入流量检查和分析,通过华为乾坤云平台直观的攻击源信息显示和高级情报分析,发现兰投集团OA办公系统存在wpsAssistServlet任意文件上传漏洞,由于兰投致远OA某些接口能被未授权访问,且安全防护存在不足,攻击者可以通过构造恶意请求,可在未授权的情况下上传恶意脚本文件,导致服务器或其他核心信息资产存在安全隐患。
|
机器学习/深度学习 人工智能 监控
AI在交通管理系统中的应用
AI在交通管理系统中的应用
896 23
|
安全 搜索推荐 Android开发
安卓与iOS:两大操作系统的比较
本文将深入探讨安卓和iOS两大操作系统的差异,包括它们的设计理念、用户界面、应用生态以及安全性等方面。通过对比分析,我们可以更好地理解这两个系统各自的优势和不足,从而为用户在选择手机时提供一些参考。
|
存储 边缘计算 安全
5G 边缘计算的安全保障:构建可信的边缘智能
5G 边缘计算的安全保障:构建可信的边缘智能
678 1
|
算法 安全 开发者
Copilot使用技巧
Copilot使用技巧
583 1
Copilot使用技巧
|
弹性计算 容灾 定位技术
阿里云服务器地域和可用区关系与选择参考
阿里云服务器的地域既有国内地域,也有国外地域,同一地域往往还有多个可用区可选,那么阿里云服务器的地域和可用区有什么关系,我们应该如何选择呢?本文介绍阿里云地域和可用区的概念、选择指导、两者的关系以及阿里云支持的地域和可用区列表。
1825 1
阿里云服务器地域和可用区关系与选择参考

热门文章

最新文章