From 95dee730daeafb07d685f4a9813616a8d6d123d6 Mon Sep 17 00:00:00 2001 From: Baldoph Date: Mon, 5 Nov 2018 17:39:09 +0100 Subject: [PATCH 1/2] Added a lineWidth property on MBRoundProgressView. --- MBProgressHUD.h | 6 ++++++ MBProgressHUD.m | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/MBProgressHUD.h b/MBProgressHUD.h index e9de43a89..a88fcaa2c 100644 --- a/MBProgressHUD.h +++ b/MBProgressHUD.h @@ -342,6 +342,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. */ diff --git a/MBProgressHUD.m b/MBProgressHUD.m index b96d99a0e..b3e106d3d 100644 --- a/MBProgressHUD.m +++ b/MBProgressHUD.m @@ -812,6 +812,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; } @@ -854,7 +855,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; @@ -875,7 +876,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)); From 025488e478abaadc4f1efd382247283a4949fe50 Mon Sep 17 00:00:00 2001 From: Baldoph Pourprix Date: Fri, 18 Nov 2022 16:40:30 +0100 Subject: [PATCH 2/2] differentiating margin into v and h margins --- MBProgressHUD.h | 11 +++++++++-- MBProgressHUD.m | 32 +++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/MBProgressHUD.h b/MBProgressHUD.h index a88fcaa2c..9907ada0a 100644 --- a/MBProgressHUD.h +++ b/MBProgressHUD.h @@ -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). diff --git a/MBProgressHUD.m b/MBProgressHUD.m index b3e106d3d..685e0ed11 100644 --- a/MBProgressHUD.m +++ b/MBProgressHUD.m @@ -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]; @@ -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]; @@ -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]; @@ -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]]; @@ -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 @@ -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]; } }