taobao/SVProgressHUD

Name: SVProgressHUD

Owner: Taobao, Inc.

Description: A clean and lightweight progress HUD for your iOS and tvOS app.

Forked from: SVProgressHUD/SVProgressHUD

Created: 2016-08-16 02:17:23.0

Updated: 2017-07-19 01:32:18.0

Pushed: 2016-08-15 21:20:41.0

Homepage: https://github.com/SVProgressHUD/SVProgressHUD

Size: 2320

Language: Objective-C

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

SVProgressHUD

Pod Version Pod License Pod Platform Carthage compatible

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

SVProgressHUD

Demo

Try SVProgressHUD on Appetize.io.

Installation
From CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like SVProgressHUD in your projects. First, add the following line to your Podfile:

'SVProgressHUD'

If you want to use the latest features of SVProgressHUD use normal external source dependencies.

'SVProgressHUD', :git => 'https://github.com/SVProgressHUD/SVProgressHUD.git'

This pulls from the master branch directly. We are usually careful about what we push there and this is the version we use ourselves in all of our projects.

Second, install SVProgressHUD into your project:

install
Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

ew update
ew install carthage

To integrate SVProgressHUD into your Xcode project using Carthage, specify it in your Cartfile:

ub "SVProgressHUD/SVProgressHUD"

Run carthage update to build the framework and drag the built SVProgressHUD.framework (in Carthage/Build/iOS folder) into your Xcode project (Linked Frameworks and Libraries in Targets).

Manually
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]).

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.

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

rogressHUD show];
atch_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:

oid)show;
oid)showWithStatus:(NSString*)string;

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

oid)showProgress:(CGFloat)progress;
oid)showProgress:(CGFloat)progress status:(NSString*)status;
Dismissing the HUD

The HUD can be dismissed using:

oid)dismiss;
oid)dismissWithDelay:(NSTimeInterval)delay;

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

oid)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 a little bit later. The display time depends on minimumDismissTimeInterval and the length of the given string.

oid)showInfoWithStatus:(NSString*)string;
oid)showSuccessWithStatus:(NSString*)string;
oid)showErrorWithStatus:(NSString*)string;
oid)showImage:(UIImage*)image status:(NSString*)string;
Customization

SVProgressHUD can be customized via the following methods:

oid)setDefaultStyle:(SVProgressHUDStyle)style;                  // default is SVProgressHUDStyleLight
oid)setDefaultMaskType:(SVProgressHUDMaskType)maskType;         // default is SVProgressHUDMaskTypeNone
oid)setDefaultAnimationType:(SVProgressHUDAnimationType)type;   // default is SVProgressHUDAnimationTypeFlat
oid)setMinimumSize:(CGSize)minimumSize;                         // default is CGSizeZero, can be used to avoid resizing for a larger message
oid)setRingThickness:(CGFloat)width;                            // default is 2 pt
oid)setRingRadius:(CGFloat)radius;                              // default is 18 pt
oid)setRingNoTextRadius:(CGFloat)radius;                        // default is 24 pt
oid)setCornerRadius:(CGFloat)cornerRadius;                      // default is 14 pt
oid)setFont:(UIFont*)font;                                      // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
oid)setForegroundColor:(UIColor*)color;                         // default is [UIColor blackColor], only used for SVProgressHUDStyleCustom
oid)setBackgroundColor:(UIColor*)color;                         // default is [UIColor whiteColor], only used for SVProgressHUDStyleCustom
oid)setBackgroundLayerColor:(UIColor*)color;                    // default is [UIColor colorWithWhite:0 alpha:0.4], only used for SVProgressHUDMaskTypeCustom
oid)setInfoImage:(UIImage*)image;                               // default is the bundled info image provided by Freepik
oid)setSuccessImage:(UIImage*)image;                            // default is bundled success image from Freepik
oid)setErrorImage:(UIImage*)image;                              // default is bundled error image from Freepik
oid)setViewForExtension:(UIView*)view;                          // default is nil, only used if #define SV_APP_EXTENSIONS is set
oid)setMinimumDismissTimeInterval:(NSTimeInterval)interval;     // default is 5.0 seconds
oid)setFadeInAnimationDuration:(NSTimeInterval)duration;        // default is 0.15 seconds
oid)setFadeOutAnimationDuration:(NSTimeInterval)duration;       // default is 0.15 seconds
oid)setMaxSupportedWindowLevel:(UIWindowLevel)windowLevel;      // default is UIWindowLevelNormal

Additionally SVProgressHUD supports the UIAppearance protocol for most of the above methods.

Hint

As standard SVProgressHUD offers two preconfigured styles:

If you want to use custom colors with setForegroundColor and setBackgroundColor: don't forget to set SVProgressHUDStyleCustom via setDefaultStyle:.

Notifications

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

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

SVProgressHUD also posts SVProgressHUDDidReceiveTouchEventNotification when users touch on the overall screen or SVProgressHUDDidTouchDownInsideNotification when a user touches on the HUD directly. For this notifications userInfo is not passed but the object parameter contains the UIEvent that related to the touch.

App Extensions

When using SVProgressHUD in an App Extension, #define SV_APP_EXTENSIONS to avoid using unavailable APIs. Additionally call setViewForExtension: from your extensions view controller with self.view.

Contributing to this project

If you have feature requests or bug reports, feel free to help out by sending pull requests or by creating new issues. Please take a moment to review the guidelines written by Nicolas Gallagher:

License

SVProgressHUD is distributed under the terms and conditions of the MIT license. The success, error and info icons are made by Freepik from Flaticon and are licensed under Creative Commons BY 3.0.

Credits

SVProgressHUD is brought to you by Sam Vermette, Tobias Tiemerding and contributors to the project. If you're using SVProgressHUD in your project, attribution would be very appreciated.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.