An easy-to-use HUD interface with personality.
It would be a shame for Mutual Mobile's in-house HUD interface to not be shared with the world. Now available for everyone!
MMProgressHUD is a part of Mutual Mobile's growing suite of open-source Objective-C projects:
Use the shared instance of MMProgressHUD
through either the +sharedHUD
class method or through the other suite of class convenience methods available.
Usage of MMProgressHUD can be accomplished in a single line of code:
[MMProgressHUD showWithTitle:@"Loading..." status:@"25%"];
Dismissing can be done in a number of ways and is just as simple:
/** Do some work asynchronously */
void (^completion)(void) = ^(){
[MMProgressHUD dismissWithSuccess:@"Completed!"];
}
No parent views to specify -- nothing else to think about.
Customizations on the look and feel of MMProgressHUD are optional and can be performed once during the lifetime of your application. These are shown below in the Setup section.
Use cocoapods for installation: pod 'MMProgressHUD'
If you really insist on doing things the hard way, simply include all of the files in the Source/
folder in the repository in your project. If you don't already have it in your project, you'll need to link against the QuartzCore and CoreGraphics frameworks.
The primary motivation for building MMProgressHUD was to be able to easily add fun animations as they were needed. MMProgressHUD has several presentation/dismiss animation styles depending on what you are looking for:
Use + (void)setPresentationStyle:(MMProgressHUDPresentationStyle)presentationStyle;
to modify the presentation animation.
MMProgressHUD uses CoreGraphics-drawn images for the default images. This makes it very easy to drop-in all the files to your project without having to specify bundles and other assets to copy. Just include the source and you're good to go.
MMProgressHUD is window-based, so it will display the overlay above the status bar. This means that MMProgressHUD does not muck with your view hierarchies and will stay self-contained in its own window. MMProgressHUD does not make itself the key window at any point during presentation.
MMProgressHUD supports almost arbitrary text content. As a matter of design and clutter, you probably shouldn't put too much text into a HUD, but MMProgressHUD will intelligently lay itself out depending on your text content. Changing the text and image content while the HUD is displayed will initiate an animation between the two states. This animation is very fast, yet not instantaneous in order to provide context of the state change.
MMProgressHUD supports extremely basic user input in the form of a confirmation tap from the user to initiate a "cancellation" action. After the user taps the HUD, it will enter a "confirmation" state in which the HUD changes state to let the user know the next tap will initiate some action that you define (see "Completion Blocks" below). For example, use this to let the user cancel a long-running task. The "confirmation" state resets back to the normal HUD state after a given timeout if the user has not confirmed the action. MMProgressHUD looks for a cancelBlock
when determining whether or not to enter into the "confirmation" state.
+ (void)showWithTitle:(NSString *)title
status:(NSString *)status
confirmationMessage:(NSString *)confirmation
cancelBlock:(void(^)(void))cancelBlock;
Some HUD actions can have an associated block of work attached to them to be fired when the action occurs:
dismissAnimationCompletion
- A block of work that is executed when the HUD dismissal animation is completed.cancelBlock
- A block of work that is executed when the user cancels a long-running action. When this block is non-nil, the HUD will respond to taps and enter a "confirmation" state on first tap. When a confirmation tap is performed by the user, the HUD is dismissed and this block is fired.progressCompletion
- A block of work that is executed when the HUD's progress property is fed a value >= 1.f.By default, MMProgressHUD displays an indeterminate spinner, but it also supports determinate tasks through the progress APIs. Feed MMProgressHUD a progress ([0,1]
), and it will display a progress indicator visually displaying the task progress to the user.
Currently, both radial and linear progress indicators are provided, with an API to provide an arbitrary determinate progress class that conforms to MMProgressView
.
+ (void)showProgressWithStyle:(MMProgressHUDProgressStyle)progressStyle
title:(NSString *)title
status:(NSString *)status
confirmationMessage:(NSString *)confirmation
cancelBlock:(void (^)(void))cancelBlock;
Update the progress HUD with the update APIs:
+ (void)updateProgress:(CGFloat)progress withStatus:(NSString *)status title:(NSString *)title;
+ (void)updateProgress:(CGFloat)progress withStatus:(NSString *)status;
+ (void)updateProgress:(CGFloat)progress;
When setting up your instance of MMProgressHUD, you'll need to configure the settings according to the style and behavior you're trying to achieve. You can find the available properties in MMProgressHUD.h
. These settings will persist across calls of show
and dismiss
, so you only have to set them once per instance:
overlayMode
- The type of overlay that displays behind the HUD and over your content.successImage
- The success image you would like to use for success dismissal. The default image is a white check mark.errorImage
- The error image you would like to use for error situations. The default image is a white 'X'.confirmationMessage
- A message to be displayed to the user when a cancelable HUD action is displayed.presentationStyle
- The behavior animation the HUD performs when presenting and dismissing itself.glowColor
- The glow color the HUD emits while in the cancellation confirmation state.progressStyle
- The style that the HUD inherits when the HUD is in determinate progress state.MMProgressHUD consists of a window, an overlay view, and the HUD view itself. Since MMProgressHUD is window-based, the overlay will display full-screen over the status bar. The only two pieces of information related to MMProgressHUD's visual anatomy are the text labels:
titleLabel
- The is the label at the top of the HUD above the content area.
statusLabel
- The message label that is displayed at the bottom of the HUD below the center content area. In the absence of title text, this label's font will be the bold variant.
You will never access these label properties directly, but it's useful to know which text will be displayed in which label when using the class convenience methods.
When contributing your modifications back to the rest of the community, please keep a couple of things in mind:
Created by Lars Anderson at Mutual Mobile.
Standard MIT License