Skip to content

Commit

Permalink
Merge pull request AliSoftware#17 from sbandol/master
Browse files Browse the repository at this point in the history
Radial Gradient Option
  • Loading branch information
matej committed Jun 23, 2011
2 parents ca75dc3 + 54b1714 commit 304fde3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
14 changes: 14 additions & 0 deletions Demo/Classes/HudDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ - (IBAction)showURL:(id)sender {
HUD = [[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES] retain];
}


- (IBAction)showWithGradient:(id)sender {

HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];

HUD.canShowGradient = YES;
// Regiser 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];
}

#pragma mark -
#pragma mark Execution code

Expand Down
48 changes: 44 additions & 4 deletions Demo/HudDemoViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">528</int>
<string key="IBDocument.SystemVersion">10J4139</string>
<string key="IBDocument.SystemVersion">10J4138</string>
<string key="IBDocument.InterfaceBuilderVersion">1306</string>
<string key="IBDocument.AppKitVersion">1038.35</string>
<string key="IBDocument.HIToolboxVersion">461.00</string>
Expand Down Expand Up @@ -221,6 +221,7 @@
<string key="NSFrame">{{20, 404}, {280, 40}}</string>
<reference key="NSSuperview" ref="821963304"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="8005370"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
Expand Down Expand Up @@ -258,8 +259,30 @@
</object>
<reference key="IBUINormalTitleShadowColor" ref="612289531"/>
</object>
<object class="IBUIButton" id="8005370">
<reference key="NSNextResponder" ref="821963304"/>
<int key="NSvFlags">294</int>
<string key="NSFrame">{{20, 451}, {280, 40}}</string>
<reference key="NSSuperview" ref="821963304"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">3</int>
<reference key="IBUIFont" ref="432819284"/>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">With Gradient</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, 464}</string>
<string key="NSFrameSize">{320, 501}</string>
<reference key="NSSuperview" ref="560298147"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="960472997"/>
Expand All @@ -272,7 +295,7 @@
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
</object>
<string key="NSFrameSize">{320, 464}</string>
<string key="NSFrameSize">{320, 501}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="821963304"/>
Expand Down Expand Up @@ -373,6 +396,15 @@
</object>
<int key="connectionID">78</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">showWithGradient:</string>
<reference key="source" ref="8005370"/>
<reference key="destination" ref="372490531"/>
<int key="IBEventType">7</int>
</object>
<int key="connectionID">81</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
Expand Down Expand Up @@ -417,6 +449,7 @@
<reference ref="960472997"/>
<reference ref="626654324"/>
<reference ref="295510578"/>
<reference ref="8005370"/>
</object>
<reference key="parent" ref="560298147"/>
</object>
Expand Down Expand Up @@ -465,6 +498,11 @@
<reference key="object" ref="244375631"/>
<reference key="parent" ref="821963304"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">79</int>
<reference key="object" ref="8005370"/>
<reference key="parent" ref="821963304"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
Expand All @@ -484,6 +522,7 @@
<string>54.IBPluginDependency</string>
<string>71.IBPluginDependency</string>
<string>76.IBPluginDependency</string>
<string>79.IBPluginDependency</string>
<string>8.IBPluginDependency</string>
<string>9.IBPluginDependency</string>
</object>
Expand All @@ -504,6 +543,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>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
Expand All @@ -518,7 +558,7 @@
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">78</int>
<int key="maxID">81</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand Down
6 changes: 6 additions & 0 deletions MBProgressHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ typedef enum {
*/
@property (assign) float progress;

/**
* Show HUD with a radial gradient
*/
@property (assign) BOOL canShowGradient;


/**
* Display the HUD. You need to make sure that the main thread completes its run loop soon after this method call so
* the user interface can be updated. Call this method when your task is already set-up to be executed in a new thread
Expand Down
22 changes: 21 additions & 1 deletion MBProgressHUD.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ @implementation MBProgressHUD
@synthesize customView;

@synthesize showStarted;
@synthesize canShowGradient;

- (void)setMode:(MBProgressHUDMode)newMode {
// Dont change mode if it wasn't actually changed to prevent flickering
Expand Down Expand Up @@ -574,6 +575,26 @@ - (void)hideUsingAnimation:(BOOL)animated {

- (void)drawRect:(CGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();

if (canShowGradient) {
//Gradient colours
size_t gradLocationsNum = 2;
CGFloat gradLocations[2] = { 0.0, 1.0 };
CGFloat gradColors[8] = { 0,0,0,0.0, 0,0,0,0.75};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents (colorSpace, gradColors, gradLocations, gradLocationsNum);

//Gradient center
CGPoint gradCenter= CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
//Gradient radius
float gradRadius = MIN(self.bounds.size.width , self.bounds.size.height) ;
//Gradient draw
CGContextDrawRadialGradient (context, gradient, gradCenter,
0, gradCenter, gradRadius,
kCGGradientDrawsAfterEndLocation);
}

// Center HUD
CGRect allRect = self.bounds;
// Draw rounded HUD bacgroud rect
Expand All @@ -582,7 +603,6 @@ - (void)drawRect:(CGRect)rect {
// Corner radius
float radius = 10.0f;

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextSetGrayFillColor(context, 0.0f, self.opacity);
CGContextMoveToPoint(context, CGRectGetMinX(boxRect) + radius, CGRectGetMinY(boxRect));
Expand Down

0 comments on commit 304fde3

Please sign in to comment.