SVProgressHUD/SVProgressHUD


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

https://github.com/SVProgressHUD/SVProgressHUD

License: MIT

Language: Objective-C

Keywords: carthage, cocoapods, hud, ios, objective-c, progress, svprogresshud, tvos


SVProgressHUD

Pod Version Pod Platform Pod License Carthage compatible CocoaPods 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:

pod 'SVProgressHUD'

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

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

This pulls from the master branch directly.

Second, install SVProgressHUD into your project:

pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate SVProgressHUD into your Xcode project using Carthage, specify it in your Cartfile:

github "SVProgressHUD/SVProgressHUD"

Run carthage bootstrap to build the framework in your repository's Carthage directory. You can then include it in your target's carthage copy-frameworks build phase. For more information on this, please see Carthage's documentation.

Manually

  • Drag the SVProgressHUD/SVProgressHUD folder into your project.
  • Take care that SVProgressHUD.bundle is added to Targets->Build Phases->Copy Bundle Resources.
  • Add the QuartzCore framework to your project.

Swift

Even though SVProgressHUD is written in Objective-C, it can be used in Swift with no hassle. If you use CocoaPods add the following line to your Podfile:

use_frameworks!

If you added SVProgressHUD manually, just add a bridging header file to your project with the SVProgressHUD header included.

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):

[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)showWithStatus:(NSString*)string;

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;

Dismissing the HUD

The HUD can be dismissed using:

+ (void)dismiss;
+ (void)dismissWithDelay:(NSTimeInterval)delay;

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

+ (void)showInfoWithStatus:(NSString*)string;
+ (void)showSuccessWithStatus:(NSString*)string;
+ (void)showErrorWithStatus:(NSString*)string;
+ (void)showImage:(UIImage*)image status:(NSString*)string;

Customization

SVProgressHUD can be customized via the following methods:

+ (void)setDefaultStyle:(SVProgressHUDStyle)style;                  // default is SVProgressHUDStyleLight
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType;         // default is SVProgressHUDMaskTypeNone
+ (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type;   // default is SVProgressHUDAnimationTypeFlat
+ (void)setContainerView:(UIView*)containerView;                    // default is window level
+ (void)setMinimumSize:(CGSize)minimumSize;                         // default is CGSizeZero, can be used to avoid resizing
+ (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)setBorderColor:(nonnull UIColor*)color;                     // default is nil
+ (void)setBorderWidth:(CGFloat)width;                              // default is 0
+ (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)setImageViewSize:(CGSize)size;                              // default is 28x28 pt
+ (void)setShouldTintImages:(BOOL)shouldTintImages;                 // default is YES
+ (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)setGraceTimeInterval:(NSTimeInterval)interval;              // default is 0 seconds
+ (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval;     // default is 5.0 seconds
+ (void)setMaximumDismissTimeInterval:(NSTimeInterval)interval;     // default is CGFLOAT_MAX
+ (void)setFadeInAnimationDuration:(NSTimeInterval)duration;        // default is 0.15 seconds
+ (void)setFadeOutAnimationDuration:(NSTimeInterval)duration;       // default is 0.15 seconds
+ (void)setMaxSupportedWindowLevel:(UIWindowLevel)windowLevel;      // default is UIWindowLevelNormal
+ (void)setHapticsEnabled:(BOOL)hapticsEnabled;                     // default is NO

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

Hint

As standard SVProgressHUD offers two preconfigured styles:

  • SVProgressHUDStyleLight: White background with black spinner and text
  • SVProgressHUDStyleDark: Black background with white spinner and text

If you want to use custom colors use setForegroundColor and setBackgroundColor:. These implicitly set the HUD's style to SVProgressHUDStyleCustom.

Haptic Feedback

For users with newer devices (starting with the iPhone 7), SVProgressHUD can automatically trigger haptic feedback depending on which HUD is being displayed. The feedback maps as follows:

  • showSuccessWithStatus: <-> UINotificationFeedbackTypeSuccess
  • showInfoWithStatus: <-> UINotificationFeedbackTypeWarning
  • showErrorWithStatus: <-> UINotificationFeedbackTypeError

To enable this functionality, use setHapticsEnabled:.

Users with devices prior to iPhone 7 will have no change in functionality.

Notifications

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

  • 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 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.

Project Statistics

Sourcerank 14
Repository Size 1.02 MB
Stars 11,605
Forks 2,291
Watchers 359
Open issues 57
Dependencies 0
Contributors 91
Tags 37
Created
Last updated
Last pushed

Top Contributors See all

Tobias Tiemerding Sam Vermette Guillaume Campagna Cory Imdieke Massimiliano Bigatti Julien Saad golergka Vincent Tourraine Andrei Senchuk Matthias Tretter @CoderMay Teemu Kurppa Jon Parise Justin Williams Yasuhiro Inami David Olesch Andrei Mihailov Florent Vilmart Aaron Brager Jesse Squires

Packages Referencing this Repo

SVProgressHUD/SVProgressHUD
A clean and lightweight progress HUD for your iOS and tvOS app.
Latest release 2.2.5 - Published - 11.6K stars
SVProgressHUD-0.8.1
A clean and lightweight progress HUD for your iOS app.
Latest release 0.8 - Published - 11.6K stars
SVProgressHUD
A clean and lightweight progress HUD for your iOS and tvOS app.
Latest release 2.2.5 - Updated - 11.6K stars

Recent Tags See all

2.2.5 February 18, 2018
2.2.5 February 18, 2018
2.2.4 February 18, 2018
2.2.3 February 12, 2018
2.2.2 October 14, 2017
2.2.1 September 13, 2017
2.2 September 07, 2017
2.1.2 December 08, 2016
2.1.1 December 05, 2016
2.1 December 04, 2016
2.0.4 November 15, 2016
2.0.3 April 06, 2016
2.0.2 March 31, 2016
2.0.1 March 30, 2016
2.0 March 22, 2016

Interesting Forks See all

JaviSoto/JSProgressHUD
Fork from https://github.com/samvermette/SVProgressHUD with the ability to have a separate progre...
Objective-C - MIT - Last pushed - 15 stars - 3 forks
barrettj/SVProgressHUD
A fork of samvermette's SVProgressHUD (clean and lightweight progress HUD for your iOS app) to (o...
Objective-C - MIT - Last pushed - 13 stars - 2 forks
somtd/SVProgressHUD
A clean and lightweight progress HUD for your iOS app.
Objective-C - MIT - Last pushed - 12 stars - 6 forks
iksnae/SVProgressHUD
A clean and lightweight progress HUD for your iOS app.
Objective-C - MIT - Last pushed - 3 stars
alloy/SVProgressHUD
A clean and lightweight progress HUD for your iOS app.
Objective-C - MIT - Last pushed - 3 stars

Something wrong with this page? Make a suggestion

Last synced: 2018-02-23 23:31:09 UTC

Login to resync this repository