Skip to content
Browse files

Margin is now an exposed property.

  • Loading branch information...
1 parent 4aba246 commit 8faeea23004f22c1ff7ada75696f0acb75807dfb @matej matej committed Nov 5, 2010
Showing with 21 additions and 11 deletions.
  1. +10 −1 MBProgressHUD.h
  2. +11 −10 MBProgressHUD.m
View
11 MBProgressHUD.h
@@ -110,6 +110,8 @@ typedef enum {
float width;
float height;
+ float margin;
+
BOOL taskInProgress;
float graceTime;
float minShowTime;
@@ -232,10 +234,17 @@ typedef enum {
@property (assign) float xOffset;
/**
- *The y-ayis offset of the HUD relative to the centre of the superview.
+ * The y-ayis offset of the HUD relative to the centre of the superview.
*/
@property (assign) float yOffset;
+/**
+ * The amounth of space between the HUD edge and the HUD elements (labels, indicators or custom views).
+ *
+ * Defaults to 20.0
+ */
+@property (assign) float margin;
+
/*
* Grace period is the time (in seconds) that the invoked method may be run without
* showing the HUD. If the task finishes befor the grace time runs out, the HUD will
View
21 MBProgressHUD.m
@@ -48,6 +48,7 @@ @implementation MBProgressHUD
@synthesize height;
@synthesize xOffset;
@synthesize yOffset;
+@synthesize margin;
@synthesize graceTime;
@synthesize minShowTime;
@@ -178,7 +179,6 @@ - (void)updateIndicators {
#pragma mark -
#pragma mark Constants
-#define MARGIN 20.0
#define PADDING 4.0
#define LABELFONTSIZE 16.0
@@ -252,6 +252,7 @@ - (id)initWithFrame:(CGRect)frame {
self.detailsLabelFont = [UIFont boldSystemFontOfSize:LABELDETAILSFONTSIZE];
self.xOffset = 0.0;
self.yOffset = 0.0;
+ self.margin = 20.0;
self.graceTime = 0.0;
self.minShowTime = 0.0;
self.removeFromSuperViewOnHide = NO;
@@ -300,8 +301,8 @@ - (void)layoutSubviews {
// 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;
+ 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;
@@ -316,11 +317,11 @@ - (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 - 2 * margin)) {
lWidth = dims.width;
}
else {
- lWidth = frame.size.width - 4 * MARGIN;
+ lWidth = frame.size.width - 4 * margin;
}
// Set label properties
@@ -333,8 +334,8 @@ - (void)layoutSubviews {
label.text = self.labelText;
// Update HUD size
- if (self.width < (lWidth + 2 * MARGIN)) {
- self.width = lWidth + 2 * MARGIN;
+ if (self.width < (lWidth + 2 * margin)) {
+ self.width = lWidth + 2 * margin;
}
self.height = self.height + lHeight + PADDING;
@@ -357,11 +358,11 @@ - (void)layoutSubviews {
// 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)) {
+ if (dims.width <= (frame.size.width - 2 * margin)) {
lWidth = dims.width;
}
else {
- lWidth = frame.size.width - 4 * MARGIN;
+ lWidth = frame.size.width - 4 * margin;
}
// Set label properties
@@ -375,7 +376,7 @@ - (void)layoutSubviews {
// Update HUD size
if (self.width < lWidth) {
- self.width = lWidth + 2 * MARGIN;
+ self.width = lWidth + 2 * margin;
}
self.height = self.height + lHeight + PADDING;

0 comments on commit 8faeea2

Please sign in to comment.
Something went wrong with that request. Please try again.