Skip to content

Commit

Permalink
Added a Custom View mode.
Browse files Browse the repository at this point in the history
Added custom view examples to the demo project.
Changed the way indicators are created.
  • Loading branch information
matej committed Mar 27, 2010
1 parent 7068e58 commit 6408e7f
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 63 deletions.
2 changes: 2 additions & 0 deletions Demo/Classes/HudDemoViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
- (IBAction)showWithLabel:(id)sender;
- (IBAction)showWithDetailsLabel:(id)sender;
- (IBAction)showWithLabelDeterminate:(id)sender;
- (IBAction)showWithCustomView:(id)sender;
- (IBAction)showWithLabelOnly:(id)sender;
- (IBAction)showWithLabelMixed:(id)sender;

- (void)myTask;
Expand Down
32 changes: 32 additions & 0 deletions Demo/Classes/HudDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,32 @@ - (IBAction)showWithLabelDeterminate:(id)sender {
[HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];
}

- (IBAction)showWithCustomView:(id)sender {
// The hud will dispable all input on the view
HUD = [[MBProgressHUD alloc] initWithView:self.view];

// Set custom view mode
HUD.mode = MBProgressHUDModeCustomView;

// Add HUD to screen
[self.view addSubview:HUD];

// Regisete for HUD callbacks so we can remove it from the window at the right time
HUD.delegate = self;

HUD.labelText = @"Completed";

// The sample image is based on the work by www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];

// This would only show the completed text with no visible custom view
// HUD.customView = [[UIView alloc] initWithFrame:CGRectZero];

// Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];
}

- (IBAction)showWithLabelMixed:(id)sender {
// The hud will dispable all input on the view
HUD = [[MBProgressHUD alloc] initWithView:self.view];
Expand Down Expand Up @@ -155,6 +181,12 @@ - (void)myMixedTask {
HUD.mode = MBProgressHUDModeIndeterminate;
HUD.labelText = @"Cleaning up";
sleep(2);
// The sample image is based on the work by www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
HUD.mode = MBProgressHUDModeCustomView;
HUD.labelText = @"Completed";
sleep(2);
}

#pragma mark -
Expand Down
4 changes: 4 additions & 0 deletions Demo/HudDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD733E0D9D9553002E5188 /* MainWindow.xib */; };
28D7ACF80DDB3853001CB0EB /* HudDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D7ACF70DDB3853001CB0EB /* HudDemoViewController.m */; };
D22F7D810F85241C00550BB3 /* MBProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = D22F7D800F85241C00550BB3 /* MBProgressHUD.m */; };
D2F88CD6115E9F7F00E6DB82 /* 37x-Checkmark.png in Resources */ = {isa = PBXBuildFile; fileRef = D2F88CD5115E9F7F00E6DB82 /* 37x-Checkmark.png */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -34,6 +35,7 @@
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D22F7D7F0F85241C00550BB3 /* MBProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MBProgressHUD.h; path = ../MBProgressHUD.h; sourceTree = SOURCE_ROOT; };
D22F7D800F85241C00550BB3 /* MBProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MBProgressHUD.m; path = ../../MBProgressHUD.m; sourceTree = "<group>"; };
D2F88CD5115E9F7F00E6DB82 /* 37x-Checkmark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "37x-Checkmark.png"; path = "Images/37x-Checkmark.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -95,6 +97,7 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
D2F88CD5115E9F7F00E6DB82 /* 37x-Checkmark.png */,
2899E5210DE3E06400AC0155 /* HudDemoViewController.xib */,
28AD733E0D9D9553002E5188 /* MainWindow.xib */,
8D1107310486CEB800E47090 /* Info.plist */,
Expand Down Expand Up @@ -156,6 +159,7 @@
files = (
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */,
2899E5220DE3E06400AC0155 /* HudDemoViewController.xib in Resources */,
D2F88CD6115E9F7F00E6DB82 /* 37x-Checkmark.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
56 changes: 48 additions & 8 deletions Demo/HudDemoViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">3</int>
<object class="NSFont" key="IBUIFont" id="432819284">
<string key="NSName">Helvetica-Bold</string>
<double key="NSSize">15</double>
Expand Down Expand Up @@ -77,7 +77,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">3</int>
<reference key="IBUIFont" ref="432819284"/>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">With label</string>
Expand All @@ -96,7 +96,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">3</int>
<reference key="IBUIFont" ref="432819284"/>
<int key="IBUIButtonType">1</int>
<string key="IBUIHighlightedTitle">With details label</string>
Expand All @@ -118,7 +118,7 @@
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">3</int>
<reference key="IBUIFont" ref="432819284"/>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">Determinate mode</string>
Expand All @@ -132,12 +132,12 @@
<object class="IBUIButton" id="319652209">
<reference key="NSNextResponder" ref="774585933"/>
<int key="NSvFlags">294</int>
<string key="NSFrame">{{20, 212}, {280, 40}}</string>
<string key="NSFrame">{{20, 260}, {280, 40}}</string>
<reference key="NSSuperview" ref="774585933"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">3</int>
<reference key="IBUIFont" ref="432819284"/>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">Mode switching</string>
Expand All @@ -148,12 +148,31 @@
</object>
<reference key="IBUINormalTitleShadowColor" ref="612289531"/>
</object>
<object class="IBUIButton" id="424785">
<reference key="NSNextResponder" ref="774585933"/>
<int key="NSvFlags">294</int>
<string key="NSFrame">{{20, 212}, {280, 40}}</string>
<reference key="NSSuperview" ref="774585933"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">3</int>
<reference key="IBUIFont" ref="432819284"/>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">Custom view</string>
<reference key="IBUIHighlightedTitleColor" ref="434568641"/>
<object class="NSColor" key="IBUINormalTitleColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA</bytes>
</object>
<reference key="IBUINormalTitleShadowColor" ref="612289531"/>
</object>
</object>
<string key="NSFrameSize">{320, 460}</string>
<reference key="NSSuperview"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC43NjQ0MTc3MSAwLjgxMjIyNzg1IDAuODIxMTc5NTEAA</bytes>
<bytes key="NSRGB">MC44ODYyNzQ1MDk4IDAuOTA1ODgyMzUyOSAwLjkyOTQxMTc2NDcAA</bytes>
</object>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
Expand Down Expand Up @@ -215,6 +234,15 @@
</object>
<int key="connectionID">21</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">showWithCustomView:</string>
<reference key="source" ref="424785"/>
<reference key="destination" ref="372490531"/>
<int key="IBEventType">7</int>
</object>
<int key="connectionID">47</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
Expand Down Expand Up @@ -245,6 +273,7 @@
<reference ref="626654324"/>
<reference ref="244375631"/>
<reference ref="322519489"/>
<reference ref="424785"/>
<reference ref="319652209"/>
</object>
<reference key="parent" ref="0"/>
Expand Down Expand Up @@ -274,6 +303,11 @@
<reference key="object" ref="960472997"/>
<reference key="parent" ref="774585933"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">43</int>
<reference key="object" ref="424785"/>
<reference key="parent" ref="774585933"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
Expand All @@ -285,6 +319,7 @@
<string>10.IBPluginDependency</string>
<string>16.IBPluginDependency</string>
<string>20.IBPluginDependency</string>
<string>43.IBPluginDependency</string>
<string>6.IBEditorWindowLastContentRect</string>
<string>6.IBPluginDependency</string>
<string>8.IBPluginDependency</string>
Expand All @@ -297,6 +332,7 @@
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>{{179, 181}, {320, 480}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
Expand All @@ -319,7 +355,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">42</int>
<int key="maxID">48</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand All @@ -332,10 +368,12 @@
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>showSimple:</string>
<string>showWithCustomView:</string>
<string>showWithDetailsLabel:</string>
<string>showWithLabel:</string>
<string>showWithLabelDeterminate:</string>
<string>showWithLabelMixed:</string>
<string>showWithLabelOnly:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -344,6 +382,8 @@
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
Expand Down
Binary file added Demo/Images/37x-Checkmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 18 additions & 8 deletions MBProgressHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ typedef enum {
MBProgressHUDModeIndeterminate,
/** Progress is shown using a MBRoundProgressView. */
MBProgressHUDModeDeterminate,
/** Shows a custom view */
MBProgressHUDModeCustomView
} MBProgressHUDMode;


Expand All @@ -57,7 +59,7 @@ typedef enum {
* A progress view for showing definite progress by filling up a circle (similar to the indicator for building in xcode).
*/
@interface MBRoundProgressView : UIProgressView {

}

/**
Expand Down Expand Up @@ -85,15 +87,15 @@ typedef enum {
@interface MBProgressHUD : UIView {

MBProgressHUDMode mode;

SEL methodForExecution;
id targetForExecution;
id objectForExecution;
BOOL useAnimation;

float yOffset;
float xOffset;

float width;
float height;

Expand All @@ -103,21 +105,23 @@ typedef enum {
NSTimer *graceTimer;
NSTimer *minShowTimer;
NSDate *showStarted;

UIView *indicator;
UILabel *label;
UILabel *detailsLabel;

float progress;

id<MBProgressHUDDelegate> delegate;
NSString *labelText;
NSString *detailsLabelText;
float opacity;
UIFont *labelFont;
UIFont *detailsLabelFont;

BOOL isFinished;

UIView *customView;
}

/**
Expand All @@ -138,6 +142,12 @@ typedef enum {
*/
- (id)initWithView:(UIView *)view;

/**
* The UIView (i.g., a UIIMageView) to be shown when the HUD is in MBProgressHUDModeCustomView.
* For best results use a 37 by 37 pixel view (so the bounds match the build in indicator bounds).
*/
@property (retain) UIView *customView;

/**
* MBProgressHUD operation mode. Switches between indeterminate (MBProgressHUDModeIndeterminate) and determinate
* progress (MBProgressHUDModeDeterminate). The default is MBProgressHUDModeIndeterminate.
Expand Down
Loading

0 comments on commit 6408e7f

Please sign in to comment.