Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb43acfe96 | |||
| 6408e7f74d | |||
| 7068e58097 | |||
| 1574831012 | |||
| 3dec0a22f0 |
@@ -17,6 +17,7 @@
|
||||
- (IBAction)showWithLabel:(id)sender;
|
||||
- (IBAction)showWithDetailsLabel:(id)sender;
|
||||
- (IBAction)showWithLabelDeterminate:(id)sender;
|
||||
- (IBAction)showWithCustomView:(id)sender;
|
||||
- (IBAction)showWithLabelMixed:(id)sender;
|
||||
|
||||
- (void)myTask;
|
||||
|
||||
@@ -19,11 +19,10 @@
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
// No autoroation support for the HUD since we aren't using a ViewController but rather adding
|
||||
// the HUD view as a direct subview of the window.
|
||||
// You need to explicitly transform the HUD if you need a rotated version (i.g.,
|
||||
// No autoroation support when adding the HUD to a window!
|
||||
// In that case you need to explicitly transform the HUD if you need a rotated version (i.g.,
|
||||
// self.transform = CGAffineTransformMakeRotation(PI / 2); )
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
@@ -34,94 +33,112 @@
|
||||
#pragma mark IBActions
|
||||
|
||||
- (IBAction)showSimple:(id)sender {
|
||||
// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
|
||||
UIWindow *window = [UIApplication sharedApplication].keyWindow;
|
||||
HUD = [[MBProgressHUD alloc] initWithWindow:window];
|
||||
// The hud will dispable all input on the view
|
||||
HUD = [[MBProgressHUD alloc] initWithView:self.view];
|
||||
|
||||
//HUD.graceTime = 0.5;
|
||||
//HUD.minShowTime = 5.0;
|
||||
|
||||
|
||||
// Add HUD to screen
|
||||
[window addSubview:HUD];
|
||||
|
||||
[self.view addSubview:HUD];
|
||||
|
||||
// Regisete for HUD callbacks so we can remove it from the window at the right time
|
||||
HUD.delegate = self;
|
||||
|
||||
|
||||
// Show the HUD while the provided method executes in a new thread
|
||||
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
|
||||
}
|
||||
|
||||
- (IBAction)showWithLabel:(id)sender {
|
||||
// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
|
||||
UIWindow *window = [UIApplication sharedApplication].keyWindow;
|
||||
HUD = [[MBProgressHUD alloc] initWithWindow:window];
|
||||
|
||||
// The hud will dispable all input on the view
|
||||
HUD = [[MBProgressHUD alloc] initWithView:self.view];
|
||||
|
||||
// Add HUD to screen
|
||||
[window addSubview:HUD];
|
||||
|
||||
[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 = @"Loading";
|
||||
|
||||
|
||||
// Show the HUD while the provided method executes in a new thread
|
||||
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
|
||||
}
|
||||
|
||||
- (IBAction)showWithDetailsLabel:(id)sender {
|
||||
|
||||
// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
|
||||
UIWindow *window = [UIApplication sharedApplication].keyWindow;
|
||||
HUD = [[MBProgressHUD alloc] initWithWindow:window];
|
||||
|
||||
// The hud will dispable all input on the view
|
||||
HUD = [[MBProgressHUD alloc] initWithView:self.view];
|
||||
|
||||
// Add HUD to screen
|
||||
[window addSubview:HUD];
|
||||
|
||||
[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 = @"Loading";
|
||||
HUD.detailsLabelText = @"updating data";
|
||||
|
||||
|
||||
// Show the HUD while the provided method executes in a new thread
|
||||
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
|
||||
}
|
||||
|
||||
- (IBAction)showWithLabelDeterminate:(id)sender {
|
||||
|
||||
// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
|
||||
UIWindow *window = [UIApplication sharedApplication].keyWindow;
|
||||
HUD = [[MBProgressHUD alloc] initWithWindow:window];
|
||||
|
||||
// The hud will dispable all input on the view
|
||||
HUD = [[MBProgressHUD alloc] initWithView:self.view];
|
||||
|
||||
// Set determinate mode
|
||||
HUD.mode = MBProgressHUDModeDeterminate;
|
||||
|
||||
|
||||
// Add HUD to screen
|
||||
[window addSubview:HUD];
|
||||
|
||||
[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 = @"Loading";
|
||||
|
||||
|
||||
// Show the HUD while the provided method executes in a new thread
|
||||
[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 {
|
||||
|
||||
// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
|
||||
UIWindow *window = [UIApplication sharedApplication].keyWindow;
|
||||
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
|
||||
|
||||
// The hud will dispable all input on the view
|
||||
HUD = [[MBProgressHUD alloc] initWithView:self.view];
|
||||
|
||||
// Add HUD to screen
|
||||
[window addSubview:HUD];
|
||||
|
||||
[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 = @"Connecting";
|
||||
|
||||
|
||||
// Show the HUD while the provided method executes in a new thread
|
||||
[HUD showWhileExecuting:@selector(myMixedTask) onTarget:self withObject:nil animated:YES];
|
||||
}
|
||||
@@ -164,6 +181,12 @@
|
||||
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 -
|
||||
|
||||
@@ -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 */
|
||||
@@ -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 */
|
||||
@@ -95,6 +97,7 @@
|
||||
29B97317FDCFA39411CA2CEA /* Resources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D2F88CD5115E9F7F00E6DB82 /* 37x-Checkmark.png */,
|
||||
2899E5210DE3E06400AC0155 /* HudDemoViewController.xib */,
|
||||
28AD733E0D9D9553002E5188 /* MainWindow.xib */,
|
||||
8D1107310486CEB800E47090 /* Info.plist */,
|
||||
@@ -156,6 +159,7 @@
|
||||
files = (
|
||||
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */,
|
||||
2899E5220DE3E06400AC0155 /* HudDemoViewController.xib in Resources */,
|
||||
D2F88CD6115E9F7F00E6DB82 /* 37x-Checkmark.png in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -130,6 +130,25 @@
|
||||
<reference key="IBUINormalTitleShadowColor" ref="612289531"/>
|
||||
</object>
|
||||
<object class="IBUIButton" id="319652209">
|
||||
<reference key="NSNextResponder" ref="774585933"/>
|
||||
<int key="NSvFlags">294</int>
|
||||
<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">3</int>
|
||||
<reference key="IBUIFont" ref="432819284"/>
|
||||
<int key="IBUIButtonType">1</int>
|
||||
<string key="IBUINormalTitle">Mode switching</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 class="IBUIButton" id="424785">
|
||||
<reference key="NSNextResponder" ref="774585933"/>
|
||||
<int key="NSvFlags">294</int>
|
||||
<string key="NSFrame">{{20, 212}, {280, 40}}</string>
|
||||
@@ -137,10 +156,10 @@
|
||||
<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>
|
||||
<string key="IBUINormalTitle">Custom view</string>
|
||||
<reference key="IBUIHighlightedTitleColor" ref="434568641"/>
|
||||
<object class="NSColor" key="IBUINormalTitleColor">
|
||||
<int key="NSColorSpace">1</int>
|
||||
@@ -153,7 +172,7 @@
|
||||
<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"/>
|
||||
@@ -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">
|
||||
@@ -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"/>
|
||||
@@ -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">
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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">
|
||||
@@ -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>
|
||||
@@ -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">
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
+27
-13
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MBProgressHUD.h
|
||||
// Version 0.32
|
||||
// Created by Matej Bukovinski on 04.01.10.
|
||||
// Version 0.33
|
||||
// Created by Matej Bukovinski on 2.4.09.
|
||||
//
|
||||
|
||||
// This code is distributed under the terms and conditions of the MIT license.
|
||||
@@ -36,6 +36,8 @@ typedef enum {
|
||||
MBProgressHUDModeIndeterminate,
|
||||
/** Progress is shown using a MBRoundProgressView. */
|
||||
MBProgressHUDModeDeterminate,
|
||||
/** Shows a custom view */
|
||||
MBProgressHUDModeCustomView
|
||||
} MBProgressHUDMode;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +71,7 @@ typedef enum {
|
||||
@end
|
||||
|
||||
/**
|
||||
* Displays a simple HUD window containing a UIActivityIndicatorView and two optional labels for short messages.
|
||||
* Displays a simple HUD window containing a progress indicator and two optional labels for short messages.
|
||||
*
|
||||
* This is a simple drop-in class for displaying a progress HUD view similar to Apples private UIProgressHUD class.
|
||||
* The MBProgressHUD window spans over the entire space given to it by the initWithFrame constructor and catches all
|
||||
@@ -77,23 +79,27 @@ typedef enum {
|
||||
* drawn centered as a rounded semi-transparent view witch resizes depending on the user specified content.
|
||||
*
|
||||
* This view supports three modes of operation:
|
||||
* - The default mode displays just a UIActivityIndicatorView.
|
||||
* - MBProgressHUDModeIndeterminate - shows a UIActivityIndicatorView
|
||||
* - MBProgressHUDModeDeterminate - shows a custom round progress indicator (MBRoundProgressView)
|
||||
* - MBProgressHUDModeCustomView - shows an arbitrary, user specified view (@see customView)
|
||||
*
|
||||
* All three modes can have optional labels assigned:
|
||||
* - If the labelText property is set and non-empty then a label containing the provided content is placed below the
|
||||
* UIActivityIndicatorView.
|
||||
* indicator view.
|
||||
* - If also the detailsLabelText property is set then another label is placed below the first label.
|
||||
*/
|
||||
@interface MBProgressHUD : UIView {
|
||||
|
||||
MBProgressHUDMode mode;
|
||||
|
||||
|
||||
SEL methodForExecution;
|
||||
id targetForExecution;
|
||||
id objectForExecution;
|
||||
BOOL useAnimation;
|
||||
|
||||
|
||||
float yOffset;
|
||||
float xOffset;
|
||||
|
||||
|
||||
float width;
|
||||
float height;
|
||||
|
||||
@@ -103,21 +109,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,6 +146,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.
|
||||
|
||||
+55
-49
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MBProgressHUD.m
|
||||
// Version 0.32
|
||||
// Created by Matej Bukovinski on 04.01.10.
|
||||
// Version 0.33
|
||||
// Created by Matej Bukovinski on 2.4.09.
|
||||
//
|
||||
|
||||
#import "MBProgressHUD.h"
|
||||
@@ -64,6 +64,8 @@
|
||||
@synthesize minShowTimer;
|
||||
@synthesize taskInProgress;
|
||||
|
||||
@synthesize customView;
|
||||
|
||||
@synthesize showStarted;
|
||||
|
||||
- (void)setMode:(MBProgressHUDMode)newMode {
|
||||
@@ -71,9 +73,9 @@
|
||||
if (mode && (mode == newMode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
mode = newMode;
|
||||
|
||||
|
||||
[self performSelectorOnMainThread:@selector(updateIndicators) withObject:nil waitUntilDone:NO];
|
||||
[self performSelectorOnMainThread:@selector(setNeedsLayout) withObject:nil waitUntilDone:NO];
|
||||
[self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
|
||||
@@ -93,7 +95,7 @@
|
||||
|
||||
- (void)setProgress:(float)newProgress {
|
||||
progress = newProgress;
|
||||
|
||||
|
||||
// Update display ony if showing the determinate progress view
|
||||
if (mode == MBProgressHUDModeDeterminate) {
|
||||
[self performSelectorOnMainThread:@selector(updateProgress) withObject:nil waitUntilDone:NO];
|
||||
@@ -126,18 +128,19 @@
|
||||
if (indicator) {
|
||||
[indicator removeFromSuperview];
|
||||
}
|
||||
|
||||
self.indicator = nil;
|
||||
|
||||
if (mode == MBProgressHUDModeDeterminate) {
|
||||
self.indicator = [[MBRoundProgressView alloc] initWithDefaultSize];
|
||||
self.indicator = [[[MBRoundProgressView alloc] initWithDefaultSize] autorelease];
|
||||
}
|
||||
else {
|
||||
self.indicator = [[UIActivityIndicatorView alloc]
|
||||
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
||||
else if (mode == MBProgressHUDModeCustomView && self.customView != nil){
|
||||
self.indicator = self.customView;
|
||||
} else {
|
||||
self.indicator = [[[UIActivityIndicatorView alloc]
|
||||
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
|
||||
[(UIActivityIndicatorView *)indicator startAnimating];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
[self addSubview:indicator];
|
||||
}
|
||||
|
||||
@@ -181,17 +184,19 @@
|
||||
self.yOffset = 0.0;
|
||||
self.graceTime = 0.0;
|
||||
self.minShowTime = 0.0;
|
||||
|
||||
|
||||
self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
|
||||
|
||||
// Transparent background
|
||||
self.opaque = NO;
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
|
||||
|
||||
// Make invisible for now
|
||||
self.alpha = 0.0;
|
||||
|
||||
|
||||
// Add label
|
||||
label = [[UILabel alloc] initWithFrame:self.bounds];
|
||||
|
||||
|
||||
// Add details label
|
||||
detailsLabel = [[UILabel alloc] initWithFrame:self.bounds];
|
||||
|
||||
@@ -209,6 +214,7 @@
|
||||
[graceTimer release];
|
||||
[minShowTimer release];
|
||||
[showStarted release];
|
||||
[customView release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -217,22 +223,22 @@
|
||||
|
||||
- (void)layoutSubviews {
|
||||
CGRect frame = self.bounds;
|
||||
|
||||
|
||||
// Compute HUD dimensions based on indicator size (add margin to HUD border)
|
||||
CGRect indFrame = indicator.bounds;
|
||||
self.width = indFrame.size.width + 2 * MARGIN;
|
||||
self.height = indFrame.size.height + 2 * MARGIN;
|
||||
|
||||
|
||||
// Position the indicator
|
||||
indFrame.origin.x = floor((frame.size.width - indFrame.size.width) / 2) + self.xOffset;
|
||||
indFrame.origin.y = floor((frame.size.height - indFrame.size.height) / 2) + self.yOffset;
|
||||
indicator.frame = indFrame;
|
||||
|
||||
|
||||
// Add label if label text was set
|
||||
if (nil != self.labelText) {
|
||||
// Get size of label text
|
||||
CGSize dims = [self.labelText sizeWithFont:self.labelFont];
|
||||
|
||||
|
||||
// Compute label dimensions based on font metrics if size is larger than max then clip the label width
|
||||
float lHeight = dims.height;
|
||||
float lWidth;
|
||||
@@ -242,7 +248,7 @@
|
||||
else {
|
||||
lWidth = frame.size.width - 4 * MARGIN;
|
||||
}
|
||||
|
||||
|
||||
// Set label properties
|
||||
label.font = self.labelFont;
|
||||
label.adjustsFontSizeToFitWidth = NO;
|
||||
@@ -251,30 +257,30 @@
|
||||
label.backgroundColor = [UIColor clearColor];
|
||||
label.textColor = [UIColor whiteColor];
|
||||
label.text = self.labelText;
|
||||
|
||||
|
||||
// Update HUD size
|
||||
if (self.width < (lWidth + 2 * MARGIN)) {
|
||||
self.width = lWidth + 2 * MARGIN;
|
||||
}
|
||||
self.height = self.height + lHeight + PADDING;
|
||||
|
||||
|
||||
// Move indicator to make room for the label
|
||||
indFrame.origin.y -= (floor(lHeight / 2 + PADDING / 2));
|
||||
indicator.frame = indFrame;
|
||||
|
||||
|
||||
// Set the label position and dimensions
|
||||
CGRect lFrame = CGRectMake(floor((frame.size.width - lWidth) / 2) + xOffset,
|
||||
floor(indFrame.origin.y + indFrame.size.height + PADDING),
|
||||
lWidth, lHeight);
|
||||
label.frame = lFrame;
|
||||
|
||||
|
||||
[self addSubview:label];
|
||||
|
||||
|
||||
// Add details label delatils text was set
|
||||
if (nil != self.detailsLabelText) {
|
||||
// Get size of label text
|
||||
dims = [self.detailsLabelText sizeWithFont:self.detailsLabelFont];
|
||||
|
||||
|
||||
// Compute label dimensions based on font metrics if size is larger than max then clip the label width
|
||||
lHeight = dims.height;
|
||||
if (dims.width <= (frame.size.width - 2 * MARGIN)) {
|
||||
@@ -283,7 +289,7 @@
|
||||
else {
|
||||
lWidth = frame.size.width - 4 * MARGIN;
|
||||
}
|
||||
|
||||
|
||||
// Set label properties
|
||||
detailsLabel.font = self.detailsLabelFont;
|
||||
detailsLabel.adjustsFontSizeToFitWidth = NO;
|
||||
@@ -292,26 +298,26 @@
|
||||
detailsLabel.backgroundColor = [UIColor clearColor];
|
||||
detailsLabel.textColor = [UIColor whiteColor];
|
||||
detailsLabel.text = self.detailsLabelText;
|
||||
|
||||
|
||||
// Update HUD size
|
||||
if (self.width < lWidth) {
|
||||
self.width = lWidth + 2 * MARGIN;
|
||||
}
|
||||
self.height = self.height + lHeight + PADDING;
|
||||
|
||||
|
||||
// Move indicator to make room for the new label
|
||||
indFrame.origin.y -= (floor(lHeight / 2 + PADDING / 2));
|
||||
indicator.frame = indFrame;
|
||||
|
||||
|
||||
// Move first label to make room for the new label
|
||||
lFrame.origin.y -= (floor(lHeight / 2 + PADDING / 2));
|
||||
label.frame = lFrame;
|
||||
|
||||
|
||||
// Set label position and dimensions
|
||||
CGRect lFrameD = CGRectMake(floor((frame.size.width - lWidth) / 2) + xOffset,
|
||||
lFrame.origin.y + lFrame.size.height + PADDING, lWidth, lHeight);
|
||||
detailsLabel.frame = lFrameD;
|
||||
|
||||
|
||||
[self addSubview:detailsLabel];
|
||||
}
|
||||
}
|
||||
@@ -372,11 +378,11 @@
|
||||
}
|
||||
|
||||
- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated {
|
||||
|
||||
|
||||
methodForExecution = method;
|
||||
targetForExecution = [target retain];
|
||||
objectForExecution = [object retain];
|
||||
|
||||
|
||||
// Launch execution in new thread
|
||||
taskInProgress = YES;
|
||||
[NSThread detachNewThreadSelector:@selector(launchExecution) toTarget:self withObject:nil];
|
||||
@@ -387,14 +393,14 @@
|
||||
|
||||
- (void)launchExecution {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
// Start executing the requested task
|
||||
[targetForExecution performSelector:methodForExecution withObject:objectForExecution];
|
||||
|
||||
|
||||
// Task completed, update view in main thread (note: view operations should
|
||||
// be done only in the main thread)
|
||||
[self performSelectorOnMainThread:@selector(cleanUp) withObject:nil waitUntilDone:NO];
|
||||
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
@@ -404,14 +410,14 @@
|
||||
|
||||
- (void)done {
|
||||
isFinished = YES;
|
||||
|
||||
|
||||
// If delegate was set make the callback
|
||||
self.alpha = 0.0;
|
||||
|
||||
if(delegate != nil && [delegate conformsToProtocol:@protocol(MBProgressHUDDelegate)]) {
|
||||
if([delegate respondsToSelector:@selector(hudWasHidden)]) {
|
||||
[delegate performSelector:@selector(hudWasHidden)];
|
||||
}
|
||||
if([delegate respondsToSelector:@selector(hudWasHidden)]) {
|
||||
[delegate performSelector:@selector(hudWasHidden)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,10 +425,10 @@
|
||||
taskInProgress = NO;
|
||||
|
||||
self.indicator = nil;
|
||||
|
||||
|
||||
[targetForExecution release];
|
||||
[objectForExecution release];
|
||||
|
||||
|
||||
[self hide:useAnimation];
|
||||
}
|
||||
|
||||
@@ -475,7 +481,7 @@
|
||||
|
||||
- (void)fillRoundedRect:(CGRect)rect inContext:(CGContextRef)context {
|
||||
float radius = 10.0f;
|
||||
|
||||
|
||||
CGContextBeginPath(context);
|
||||
CGContextSetGrayFillColor(context, 0.0, self.opacity);
|
||||
CGContextMoveToPoint(context, CGRectGetMinX(rect) + radius, CGRectGetMinY(rect));
|
||||
@@ -500,16 +506,16 @@
|
||||
CGRect allRect = self.bounds;
|
||||
CGRect circleRect = CGRectMake(allRect.origin.x + 2, allRect.origin.y + 2, allRect.size.width - 4,
|
||||
allRect.size.height - 4);
|
||||
|
||||
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
|
||||
|
||||
// Draw background
|
||||
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); // white
|
||||
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.1); // translucent white
|
||||
CGContextSetLineWidth(context, 2.0);
|
||||
CGContextFillEllipseInRect(context, circleRect);
|
||||
CGContextStrokeEllipseInRect(context, circleRect);
|
||||
|
||||
|
||||
// Draw progress
|
||||
float x = (allRect.size.width / 2);
|
||||
float y = (allRect.size.height / 2);
|
||||
|
||||
@@ -7,6 +7,7 @@ MBProgressHUD is an iPhone drop-in class that displays a translucent HUD with a
|
||||
[](http://grab.by/grabs/37edc22342fcafee5cb6480f1114e882.png)
|
||||
[](http://grab.by/grabs/11295a7e38b0cfda85b173612f03c2b6.png)
|
||||
[](http://grab.by/grabs/b72d772d1b578fe78b40ae30cd6ac66e.png)
|
||||
[](http://grab.by/grabs/b2608a107117932ea8c8f5304c34e9e2.png)
|
||||
|
||||
Adding MBProgressHUD to your project
|
||||
====================================
|
||||
@@ -26,6 +27,10 @@ A full Xcode demo project is included in the Demo directory. This should give yo
|
||||
Change-log
|
||||
==========
|
||||
|
||||
Version 0.33 @ 27.03.10
|
||||
- Custom view operation mode added.
|
||||
- Fixed a memory leak.
|
||||
|
||||
Version 0.32 @ 4.01.10
|
||||
- Added minShowTime, graceTime, xOffset, yOffset.
|
||||
- Various fixes.
|
||||
|
||||
Reference in New Issue
Block a user