Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 215 additions & 2 deletions Demo/MMProgressHUDDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

27 changes: 0 additions & 27 deletions Source/MMHud.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,6 @@
#import <UIKit/UIKit.h>
#import "MMProgressHUDDefines.h"

MMExtern CGFloat const MMProgressHUDAnimateInDurationLong;
MMExtern CGFloat const MMProgressHUDAnimateInDurationNormal;
MMExtern CGFloat const MMProgressHUDAnimateInDurationMedium;
MMExtern CGFloat const MMProgressHUDAnimateInDurationShort;
MMExtern CGFloat const MMProgressHUDAnimateInDurationVeryShort;

MMExtern CGFloat const MMProgressHUDAnimateOutDurationLong;
MMExtern CGFloat const MMProgressHUDAnimateOutDurationMedium;
MMExtern CGFloat const MMProgressHUDAnimateOutDurationShort;

typedef NS_ENUM(NSInteger, MMProgressHUDDisplayStyle) {
MMProgressHUDDisplayStylePlain = 0,
MMProgressHUDDisplayStyleBordered,
};

typedef NS_ENUM(NSInteger, MMProgressHUDProgressStyle) {
MMProgressHUDProgressStyleIndeterminate = 0,
MMProgressHUDProgressStyleRadial,
MMProgressHUDProgressStyleLinear,
} DEPRECATED_ATTRIBUTE;

typedef NS_ENUM(NSInteger, MMProgressHUDCompletionState) {
MMProgressHUDCompletionStateNone = 0,
MMProgressHUDCompletionStateError,
MMProgressHUDCompletionStateSuccess,
};

@class MMHud;

@protocol MMHudDelegate <NSObject>
Expand Down
52 changes: 7 additions & 45 deletions Source/MMHud.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,12 @@
#import <QuartzCore/QuartzCore.h>
#import "MMHud.h"
#import "MMProgressHUD.h"
#import "MMProgressView.h"
#import "MMProgressView-Protocol.h"
#import "MMRadialProgressView.h"

CGFloat const MMProgressHUDDefaultFontSize = 16.f;
#import "MMProgressHUDDefines-Private.h"

CGFloat const MMProgressHUDMaximumWidth = 300.f;
CGFloat const MMProgressHUDMinimumWidth = 100.f;
CGFloat const MMProgressHUDContentPadding = 5.f;

CGFloat const MMProgressHUDAnimateInDurationLong = 1.5f;
CGFloat const MMProgressHUDAnimateInDurationMedium = 0.75f;
CGFloat const MMProgressHUDAnimateInDurationNormal = 0.35f;
CGFloat const MMProgressHUDAnimateInDurationShort = 0.25f;
CGFloat const MMProgressHUDAnimateInDurationVeryShort= 0.15f;

CGFloat const MMProgressHUDAnimateOutDurationLong = 0.75f;
CGFloat const MMProgressHUDAnimateOutDurationMedium = 0.55f;
CGFloat const MMProgressHUDAnimateOutDurationShort = 0.35f;

CGSize const MMProgressHUDDefaultContentAreaSize = { 100.f, 100.f };
CGSize const MMProgressHUDProgressContentAreaSize = { 40.f, 40.f };
CGSize const MMProgressHUDProgressMaximumAreaSize = {200.0f, 200.0f};


NSString * const MMProgressHUDFontNameBold = @"HelveticaNeue-Bold";
NSString * const MMProgressHUDFontNameNormal = @"HelveticaNeue-Light";

#ifdef DEBUG
#ifdef MM_HUD_FRAME_DEBUG
static const BOOL MMProgressHUDFrameDebugModeEnabled = YES;
#else
static const BOOL MMProgressHUDFrameDebugModeEnabled = NO;
#endif
#else
static const BOOL MMProgressHUDFrameDebugModeEnabled = NO;
#endif

@interface MMHud()
@interface MMHud ()

@property (nonatomic, strong) UIView *progressViewContainer;
@property (nonatomic, strong) UIView <MMProgressView> *progressView;
Expand Down Expand Up @@ -507,11 +475,8 @@ - (void)_buildStatusLabel {
_statusLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_statusLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
_statusLabel.numberOfLines = 0;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
_statusLabel.lineBreakMode = UILineBreakModeWordWrap;
_statusLabel.textAlignment = UITextAlignmentCenter;
#pragma clang diagnostic pop
_statusLabel.lineBreakMode = NSLineBreakByWordWrapping;
_statusLabel.textAlignment = NSTextAlignmentCenter;
_statusLabel.backgroundColor = [UIColor clearColor];
_statusLabel.font = [UIFont fontWithName:MMProgressHUDFontNameNormal size:MMProgressHUDDefaultFontSize];
_statusLabel.textColor = [UIColor colorWithWhite:0.9f alpha:0.95f];
Expand Down Expand Up @@ -539,11 +504,8 @@ - (void)_buildTitleLabel {
_titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_titleLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
_titleLabel.numberOfLines = 0;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
_titleLabel.lineBreakMode = UILineBreakModeWordWrap;
_titleLabel.textAlignment = UITextAlignmentCenter;
#pragma clang diagnostic pop
_titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.font = [UIFont fontWithName:MMProgressHUDFontNameBold size:MMProgressHUDDefaultFontSize];
_titleLabel.textColor = [UIColor whiteColor];
Expand Down
2 changes: 1 addition & 1 deletion Source/MMLinearProgressView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import <UIKit/UIKit.h>
#import "MMProgressView.h"
#import "MMProgressView-Protocol.h"

@interface MMLinearProgressView : UIView <MMProgressView>

Expand Down
2 changes: 2 additions & 0 deletions Source/MMProgressHUD+Animations.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#import <QuartzCore/QuartzCore.h>
#import "MMProgressHUD+Animations.h"

#import "MMProgressHUDDefines-Private.h"

@interface MMProgressHUD ()

- (CGPoint)_windowCenterForHUDAnchor:(CGPoint)anchor;
Expand Down
28 changes: 22 additions & 6 deletions Source/MMProgressHUD+Class.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
//

#import "MMProgressHUD.h"
#import "MMProgressHUDDefines-Private.h"

@interface MMProgressHUD()

- (CGPoint)_windowCenterForHUDAnchor:(CGPoint)anchor;
- (void)dismissWithCompletionState:(MMProgressHUDCompletionState)completionState
title:(NSString *)title
status:(NSString *)status
afterDelay:(float)delay;
afterDelay:(NSTimeInterval)delay;

- (void)_updateHUDAnimated:(BOOL)animated
withCompletion:(void(^)(BOOL completed))completionBlock;

- (void)show;
- (void)dismiss;
- (void)dismissAfterDelay:(NSTimeInterval)delay;

@end

Expand Down Expand Up @@ -109,6 +111,16 @@ + (void)updateProgress:(CGFloat)progress {
}

//indeterminate status

+ (void)show {
[MMProgressHUD showWithTitle:nil status:nil];
}

+ (void)showWithTitle:(NSString *)title {
[MMProgressHUD showWithTitle:title
status:nil];
}

+ (void)showWithStatus:(NSString *)status {
[MMProgressHUD showWithTitle:nil
status:status];
Expand Down Expand Up @@ -157,7 +169,7 @@ + (void)showWithTitle:(NSString *)title
[MMProgressHUD showWithTitle:title
status:status
cancelBlock:cancelBlock
images:@[image]];
images:(image != nil ? @[image] : nil)];
}

+ (void)showWithTitle:(NSString *)title
Expand Down Expand Up @@ -222,7 +234,7 @@ + (void)showWithTitle:(NSString *)title
//dismissal
+ (void)dismissWithError:(NSString *)status
title:(NSString *)title
afterDelay:(float)delay {
afterDelay:(NSTimeInterval)delay {
if ([NSThread isMainThread] == NO) {
dispatch_sync(dispatch_get_main_queue(), ^{
[[MMProgressHUD sharedHUD] dismissWithCompletionState:MMProgressHUDCompletionStateError
Expand Down Expand Up @@ -252,15 +264,15 @@ + (void)dismissWithError:(NSString *)status {
}

+ (void)dismissWithError:(NSString *)status
afterDelay:(float)delay {
afterDelay:(NSTimeInterval)delay {
[MMProgressHUD dismissWithError:status
title:nil
afterDelay:delay];
}

+ (void)dismissWithSuccess:(NSString *)status
title:(NSString *)title
afterDelay:(float)delay {
afterDelay:(NSTimeInterval)delay {
if ([NSThread isMainThread] == NO) {
dispatch_sync(dispatch_get_main_queue(), ^{
[[MMProgressHUD sharedHUD] dismissWithCompletionState:MMProgressHUDCompletionStateSuccess
Expand Down Expand Up @@ -289,10 +301,14 @@ + (void)dismissWithSuccess:(NSString *)status {
title:nil];
}

+ (void)dismissAfterDelay:(NSTimeInterval)delay {
[[MMProgressHUD sharedHUD] dismissAfterDelay:delay];
}

+ (void)dismiss {
if ([NSThread isMainThread] == NO) {
dispatch_sync(dispatch_get_main_queue(), ^{
[[MMProgressHUD sharedHUD] dismiss];
[[MMProgressHUD sharedHUD] dismiss];
});
}
else {
Expand Down
91 changes: 40 additions & 51 deletions Source/MMProgressHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,9 @@
#import <UIKit/UIKit.h>
#import "MMHud.h"

MMExtern NSString * const MMProgressHUDDefaultConfirmationMessage;

MMExtern NSString * const MMProgressHUDAnimationShow;
MMExtern NSString * const MMProgressHUDAnimationDismiss;
MMExtern NSString * const MMProgressHUDAnimationWindowFadeOut;
MMExtern NSString * const MMProgressHUDAnimationKeyShowAnimation;
MMExtern NSString * const MMProgressHUDAnimationKeyDismissAnimation;


MMExtern float const MMProgressHUDStandardDismissDelay;

@class MMProgressHUDWindow;
@class MMProgressHUDOverlayView;

typedef NS_ENUM(NSInteger, MMProgressHUDPresentationStyle) {
MMProgressHUDPresentationStyleDrop = 0, //default
MMProgressHUDPresentationStyleExpand,
MMProgressHUDPresentationStyleShrink,
MMProgressHUDPresentationStyleSwingLeft,
MMProgressHUDPresentationStyleSwingRight,
MMProgressHUDPresentationStyleBalloon,
MMProgressHUDPresentationStyleFade,
MMProgressHUDPresentationStyleNone
};

typedef NS_ENUM(NSInteger, MMProgressHUDWindowOverlayMode) {
MMProgressHUDWindowOverlayModeNone = -1,
MMProgressHUDWindowOverlayModeGradient = 0,
MMProgressHUDWindowOverlayModeLinear,
/*MMProgressHUDWindowOverlayModeBlur*/ //iOS 7 only
};

//iOS 7 only
//typedef NS_ENUM(NSInteger, MMProgressHUDOptions) {
// MMProgressHUDOptionGravityEnabled = 1 << 0,
// MMProgressHUDOptionGyroEnabled = 1 << 1,
//};

@interface MMProgressHUD : UIView

/** An enum to specify the style in which to display progress.
Expand All @@ -57,9 +22,6 @@ typedef NS_ENUM(NSInteger, MMProgressHUDWindowOverlayMode) {
*/
@property (nonatomic, assign) MMProgressHUDProgressStyle progressStyle DEPRECATED_ATTRIBUTE;

/** A boolean value that indicates whether or not the HUD has been cancelled manually. */
@property (nonatomic, assign, getter = isCancelled) BOOL cancelled;

/** The determinate progress state.

The progress ranges from 0-1.
Expand All @@ -69,6 +31,9 @@ typedef NS_ENUM(NSInteger, MMProgressHUDWindowOverlayMode) {
/** A Boolean value that indicates whether or not the HUD is visible. */
@property(nonatomic, readonly, getter = isVisible) BOOL visible;

/** A boolean value that indicates whether or not the HUD has been cancelled manually. */
@property (nonatomic, assign, getter = isCancelled) BOOL cancelled;

/** The presentation style for the HUD.

Persistent across show calls.
Expand Down Expand Up @@ -164,6 +129,34 @@ This message will be presented to the user when a cancelBlock is present after t
/** @name Presentation */
//-----------------------------------------------

/** Shows indeterminate HUD.

@warning All show methods are mutually exclusive of one another. Use the updateStatus: method to update the HUD's status while maintaining all previously set presentation attributes such as image, images, cancelBlock, title, or confirmationMessage. For example: calling showWithTitle:status: after calling showWithTitle:status:image: will wipe out the image specified in the latter call.

*/
+ (void)show;


/** Shows indeterminate HUD with specified title.

@warning All show methods are mutually exclusive of one another. Use the updateStatus: method to update the HUD's status while maintaining all previously set presentation attributes such as image, images, cancelBlock, title, or confirmationMessage. For example: calling showWithTitle:status: after calling showWithTitle:status:image: will wipe out the image specified in the latter call.

@param title Title to display.
*/
+ (void)showWithTitle:(NSString *)title;


/** Shows user-blocking HUD with only a status message.

Since the title of this HUD is nil, the status message font will become bold by default.

@warning All show methods are mutually exclusive of one another. Use the updateStatus: method to update the HUD's status while maintaining all previously set presentation attributes such as image, images, cancelBlock, title, or confirmationMessage. For example: calling showWithTitle:status: after calling showWithTitle:status:image: will wipe out the image specified in the latter call.

@param status Status message to display.
*/
+ (void)showWithStatus:(NSString *)status;


/** Shows indeterminate HUD with specified title and status.

When the title of the HUD is nil, the status message font will become bold by default.
Expand Down Expand Up @@ -301,23 +294,19 @@ This message will be presented to the user when a cancelBlock is present after t
status:(NSString *)status
images:(NSArray *)images;

/** Shows user-blocking HUD with only a status message.

Since the title of this HUD is nil, the status message font will become bold by default.

@warning All show methods are mutually exclusive of one another. Use the updateStatus: method to update the HUD's status while maintaining all previously set presentation attributes such as image, images, cancelBlock, title, or confirmationMessage. For example: calling showWithTitle:status: after calling showWithTitle:status:image: will wipe out the image specified in the latter call.

@param status Status message to display.
*/
+ (void)showWithStatus:(NSString *)status;

//-----------------------------------------------
/** @name Dismissal */
//-----------------------------------------------

/** Dismisses the shared HUD with the current presentationStyle and default delay. */
+ (void)dismiss;


/** Dismisses the shared HUD with the current presentationStyle and specified delay.
@param delay Delay to wait before animating the dismiss of the HUD.
*/
+ (void)dismissAfterDelay:(NSTimeInterval)delay;

#pragma mark - Dismiss with Error

/** Dismisses the shared HUD with the current presentationStyle in an error-state after a user-specified delay.
Expand All @@ -328,7 +317,7 @@ This message will be presented to the user when a cancelBlock is present after t
*/
+ (void)dismissWithError:(NSString *)message
title:(NSString *)title
afterDelay:(float)delay;
afterDelay:(NSTimeInterval)delay;

/** Dismisses the shared HUD with the current presentationStyle in an error-state after a standard delay.

Expand All @@ -350,7 +339,7 @@ This message will be presented to the user when a cancelBlock is present after t
@param delay Delay to wait before animating the dismiss of the HUD.
*/
+ (void)dismissWithError:(NSString *)message
afterDelay:(float)delay;
afterDelay:(NSTimeInterval)delay;

#pragma mark - Dismiss with Success
/** Dismisses the shared HUD with the current presentationStyle in a success-state after a user-specified delay.
Expand All @@ -361,7 +350,7 @@ This message will be presented to the user when a cancelBlock is present after t
*/
+ (void)dismissWithSuccess:(NSString *)message
title:(NSString *)title
afterDelay:(float)delay;
afterDelay:(NSTimeInterval)delay;

/** Dismisses the shared HUD with the current presentationStyle in a success-state.

Expand Down
Loading