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

Added a lineWidth property on MBRoundProgressView. #550

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 15 additions & 2 deletions MBProgressHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,18 @@ NS_ASSUME_NONNULL_BEGIN
@property (assign, nonatomic) CGPoint offset UI_APPEARANCE_SELECTOR;

/**
* The amount of space between the HUD edge and the HUD elements (labels, indicators or custom views).
* The vertical amount of space between the HUD edge and the HUD elements (labels, indicators or custom views).
* This also represents the minimum bezel distance to the edge of the HUD view.
* Defaults to 20.f
*/
@property (assign, nonatomic) CGFloat margin UI_APPEARANCE_SELECTOR;
@property (assign, nonatomic) CGFloat vMargin UI_APPEARANCE_SELECTOR;

/**
* The horizontal amount of space between the HUD edge and the HUD elements (labels, indicators or custom views).
* This also represents the minimum bezel distance to the edge of the HUD view.
* Defaults to 20.f
*/
@property (assign, nonatomic) CGFloat hMargin UI_APPEARANCE_SELECTOR;

/**
* The minimum size of the HUD bezel. Defaults to CGSizeZero (no minimum size).
Expand Down Expand Up @@ -342,6 +349,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, strong) UIColor *backgroundTintColor;

/**
* Indicator line width.
* Defaults to 2.0.
*/
@property (nonatomic, assign) CGFloat lineWidth;

/*
* Display mode - NO = round or YES = annular. Defaults to round.
*/
Expand Down
37 changes: 24 additions & 13 deletions MBProgressHUD.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ - (void)commonInit {
// Set default values for properties
_animationType = MBProgressHUDAnimationFade;
_mode = MBProgressHUDModeIndeterminate;
_margin = 20.0f;
_vMargin = 20.0f;
_hMargin = 20.0f;
_defaultMotionEffectsEnabled = YES;
_contentColor = [UIColor colorWithWhite:0.f alpha:0.7f];

Expand Down Expand Up @@ -499,9 +500,10 @@ - (void)updateConstraints {
UIView *bezel = self.bezelView;
UIView *topSpacer = self.topSpacer;
UIView *bottomSpacer = self.bottomSpacer;
CGFloat margin = self.margin;
CGFloat vMargin = self.vMargin;
CGFloat hMargin = self.hMargin;
NSMutableArray *bezelConstraints = [NSMutableArray array];
NSDictionary *metrics = @{@"margin": @(margin)};
NSDictionary *metrics = @{@"vMargin": @(vMargin), @"hMargin": @(hMargin)};

NSMutableArray *subviews = [NSMutableArray arrayWithObjects:self.topSpacer, self.label, self.detailsLabel, self.button, self.bottomSpacer, nil];
if (self.indicator) [subviews insertObject:self.indicator atIndex:1];
Expand All @@ -525,8 +527,8 @@ - (void)updateConstraints {

// Ensure minimum side margin is kept
NSMutableArray *sideConstraints = [NSMutableArray array];
[sideConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"|-(>=margin)-[bezel]-(>=margin)-|" options:0 metrics:metrics views:NSDictionaryOfVariableBindings(bezel)]];
[sideConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(>=margin)-[bezel]-(>=margin)-|" options:0 metrics:metrics views:NSDictionaryOfVariableBindings(bezel)]];
[sideConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"|-(>=hMargin)-[bezel]-(>=hMargin)-|" options:0 metrics:metrics views:NSDictionaryOfVariableBindings(bezel)]];
[sideConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(>=vMargin)-[bezel]-(>=vMargin)-|" options:0 metrics:metrics views:NSDictionaryOfVariableBindings(bezel)]];
[self applyPriority:999.f toConstraints:sideConstraints];
[self addConstraints:sideConstraints];

Expand All @@ -548,8 +550,8 @@ - (void)updateConstraints {
}

// Top and bottom spacing
[topSpacer addConstraint:[NSLayoutConstraint constraintWithItem:topSpacer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.f constant:margin]];
[bottomSpacer addConstraint:[NSLayoutConstraint constraintWithItem:bottomSpacer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.f constant:margin]];
[topSpacer addConstraint:[NSLayoutConstraint constraintWithItem:topSpacer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.f constant:vMargin]];
[bottomSpacer addConstraint:[NSLayoutConstraint constraintWithItem:bottomSpacer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.f constant:vMargin]];
// Top and bottom spaces should be equal
[bezelConstraints addObject:[NSLayoutConstraint constraintWithItem:topSpacer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:bottomSpacer attribute:NSLayoutAttributeHeight multiplier:1.f constant:0.f]];

Expand All @@ -559,7 +561,7 @@ - (void)updateConstraints {
// Center in bezel
[bezelConstraints addObject:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:bezel attribute:NSLayoutAttributeCenterX multiplier:1.f constant:0.f]];
// Ensure the minimum edge margin is kept
[bezelConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"|-(>=margin)-[view]-(>=margin)-|" options:0 metrics:metrics views:NSDictionaryOfVariableBindings(view)]];
[bezelConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"|-(>=hMargin)-[view]-(>=hMargin)-|" options:0 metrics:metrics views:NSDictionaryOfVariableBindings(view)]];
// Element spacing
if (idx == 0) {
// First, ensure spacing to bezel edge
Expand Down Expand Up @@ -642,9 +644,17 @@ - (void)setOffset:(CGPoint)offset {
}
}

- (void)setMargin:(CGFloat)margin {
if (margin != _margin) {
_margin = margin;

- (void)setVMargin:(CGFloat)vMargin {
if (vMargin != _vMargin) {
_vMargin = vMargin;
[self setNeedsUpdateConstraints];
}
}

- (void)setHMargin:(CGFloat)hMargin {
if (hMargin != _hMargin) {
_hMargin = hMargin;
[self setNeedsUpdateConstraints];
}
}
Expand Down Expand Up @@ -812,6 +822,7 @@ - (id)initWithFrame:(CGRect)frame {
_annular = NO;
_progressTintColor = [[UIColor alloc] initWithWhite:1.f alpha:1.f];
_backgroundTintColor = [[UIColor alloc] initWithWhite:1.f alpha:.1f];
_lineWidth = 2;
}
return self;
}
Expand Down Expand Up @@ -854,7 +865,7 @@ - (void)drawRect:(CGRect)rect {

if (_annular) {
// Draw background
CGFloat lineWidth = 2.f;
CGFloat lineWidth = _lineWidth;
UIBezierPath *processBackgroundPath = [UIBezierPath bezierPath];
processBackgroundPath.lineWidth = lineWidth;
processBackgroundPath.lineCapStyle = kCGLineCapButt;
Expand All @@ -875,7 +886,7 @@ - (void)drawRect:(CGRect)rect {
[processPath stroke];
} else {
// Draw background
CGFloat lineWidth = 2.f;
CGFloat lineWidth = _lineWidth;
CGRect allRect = self.bounds;
CGRect circleRect = CGRectInset(allRect, lineWidth/2.f, lineWidth/2.f);
CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
Expand Down