Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes #27

Merged
merged 7 commits into from
Nov 3, 2011
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
4 changes: 3 additions & 1 deletion Demo/Classes/HudDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ - (IBAction)showWithDetailsLabel:(id)sender {

HUD.delegate = self;
HUD.labelText = @"Loading";
HUD.detailsLabelText = @"updating data";
HUD.detailsLabelText = @"udating data";
HUD.square = YES;

[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}
Expand Down Expand Up @@ -119,6 +120,7 @@ - (IBAction)showWithLabelMixed:(id)sender {

HUD.delegate = self;
HUD.labelText = @"Connecting";
HUD.minSize = CGSizeMake(135.f, 135.f);

[HUD showWhileExecuting:@selector(myMixedTask) onTarget:self withObject:nil animated:YES];
}
Expand Down
12 changes: 12 additions & 0 deletions MBProgressHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ typedef enum {
float width;
float height;

CGSize minSize;
BOOL square;

float margin;

BOOL dimBackground;
Expand Down Expand Up @@ -276,6 +279,15 @@ typedef enum {
*/
@property (assign) float progress;

/**
* The minimum size of the HUD bezel. Defaults to CGSizeZero.
*/
@property (assign) CGSize minSize;

/**
* Force the HUD dimensions to be eual if possible.
*/
@property (assign, getter = isSquare) BOOL square;

/**
* Display the HUD. You need to make sure that the main thread completes its run loop soon after this method call so
Expand Down
44 changes: 32 additions & 12 deletions MBProgressHUD.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ @implementation MBProgressHUD
@synthesize height;
@synthesize xOffset;
@synthesize yOffset;
@synthesize minSize;
@synthesize square;
@synthesize margin;
@synthesize dimBackground;

Expand Down Expand Up @@ -261,6 +263,8 @@ - (id)initWithFrame:(CGRect)frame {
self.graceTime = 0.0f;
self.minShowTime = 0.0f;
self.removeFromSuperViewOnHide = NO;
self.minSize = CGSizeZero;
self.square = NO;

self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

Expand Down Expand Up @@ -322,7 +326,7 @@ - (void)layoutSubviews {
// Compute label dimensions based on font metrics if size is larger than max then clip the label width
float lHeight = dims.height;
float lWidth;
if (dims.width <= (frame.size.width - 2 * margin)) {
if (dims.width <= (frame.size.width - 4 * margin)) {
lWidth = dims.width;
}
else {
Expand Down Expand Up @@ -358,17 +362,6 @@ - (void)layoutSubviews {

// 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)) {
lWidth = dims.width;
}
else {
lWidth = frame.size.width - 4 * margin;
}

// Set label properties
detailsLabel.font = self.detailsLabelFont;
Expand All @@ -378,6 +371,12 @@ - (void)layoutSubviews {
detailsLabel.backgroundColor = [UIColor clearColor];
detailsLabel.textColor = [UIColor whiteColor];
detailsLabel.text = self.detailsLabelText;
detailsLabel.numberOfLines = 0;

CGFloat maxHeight = frame.size.height - self.height - 2*margin;
CGSize labelSize = [detailsLabel.text sizeWithFont:detailsLabel.font constrainedToSize:CGSizeMake(frame.size.width - 4*margin, maxHeight) lineBreakMode:detailsLabel.lineBreakMode];
lHeight = labelSize.height;
lWidth = labelSize.width;

// Update HUD size
if (self.width < lWidth) {
Expand All @@ -401,6 +400,23 @@ - (void)layoutSubviews {
[self addSubview:detailsLabel];
}
}

if (square) {
CGFloat max = MAX(self.width, self.height);
if (max <= frame.size.width - 2*margin) {
self.width = max;
}
if (max <= frame.size.height - 2*margin) {
self.height = max;
}
}

if (self.width < minSize.width) {
self.width = minSize.width;
}
if (self.height < minSize.height) {
self.height = minSize.height;
}
}

#pragma mark -
Expand Down Expand Up @@ -626,8 +642,12 @@ - (void)deviceOrientationDidChange:(NSNotification *)notification {
if (!self.superview) {
return;
}

if ([self.superview isKindOfClass:[UIWindow class]]) {
[self setTransformForCurrentOrientation:YES];
} else {
self.bounds = self.superview.bounds;
[self setNeedsDisplay];
}
}

Expand Down