diff --git a/Classes/ProgressViews/M13ProgressViewBar.m b/Classes/ProgressViews/M13ProgressViewBar.m index 039296b..4e9e4b1 100644 --- a/Classes/ProgressViews/M13ProgressViewBar.m +++ b/Classes/ProgressViews/M13ProgressViewBar.m @@ -182,8 +182,7 @@ - (void)setProgressBarThickness:(CGFloat)progressBarThickness [self setNeedsDisplay]; //Update strokeWidth _progressLayer.lineWidth = progressBarThickness; - //Update the corner radius - + [self invalidateIntrinsicContentSize]; } #pragma mark Actions @@ -534,6 +533,26 @@ - (void)layoutSubviews } +- (CGSize)intrinsicContentSize +{ + CGFloat labelProgressBufferDistance = _progressBarThickness * 4; + + //Progress bar thickness is the only non-scale based size parameter. + if (_progressDirection == M13ProgressViewBarProgressDirectionBottomToTop || _progressDirection == M13ProgressViewBarProgressDirectionTopToBottom) { + if (_percentagePosition == M13ProgressViewBarPercentagePositionTop || _percentagePosition == M13ProgressViewBarPercentagePositionBottom) { + return CGSizeMake(_progressBarThickness, labelProgressBufferDistance); + } else { + return CGSizeMake(_progressBarThickness + labelProgressBufferDistance, UIViewNoIntrinsicMetric); + } + } else { + if (_percentagePosition == M13ProgressViewBarPercentagePositionTop || _percentagePosition == M13ProgressViewBarPercentagePositionBottom) { + return CGSizeMake(UIViewNoIntrinsicMetric, _progressBarThickness + labelProgressBufferDistance); + } else { + return CGSizeMake(labelProgressBufferDistance, _progressBarThickness); + } + } +} + - (CGFloat)maximumFontSizeThatFitsInRect:(CGRect)frame { //Starting parameters diff --git a/Classes/ProgressViews/M13ProgressViewBorderedBar.m b/Classes/ProgressViews/M13ProgressViewBorderedBar.m index dae8c91..047e9a2 100644 --- a/Classes/ProgressViews/M13ProgressViewBorderedBar.m +++ b/Classes/ProgressViews/M13ProgressViewBorderedBar.m @@ -347,6 +347,11 @@ - (void)layoutSubviews } } +- (CGSize)intrinsicContentSize +{ + return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric); +} + #pragma mark Drawing - (void)drawRect:(CGRect)rect diff --git a/Classes/ProgressViews/M13ProgressViewFilteredImage.m b/Classes/ProgressViews/M13ProgressViewFilteredImage.m index 79af78b..e47c288 100644 --- a/Classes/ProgressViews/M13ProgressViewFilteredImage.m +++ b/Classes/ProgressViews/M13ProgressViewFilteredImage.m @@ -161,6 +161,11 @@ - (void)layoutSubviews _progressView.frame = self.bounds; } +- (CGSize)intrinsicContentSize +{ + return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric); +} + #pragma mark Drawing - (void)drawRect:(CGRect)rect diff --git a/Classes/ProgressViews/M13ProgressViewImage.m b/Classes/ProgressViews/M13ProgressViewImage.m index 7c48554..0d23502 100644 --- a/Classes/ProgressViews/M13ProgressViewImage.m +++ b/Classes/ProgressViews/M13ProgressViewImage.m @@ -170,6 +170,11 @@ - (void)layoutSubviews _progressView.frame = self.bounds; } +- (CGSize)intrinsicContentSize +{ + return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric); +} + #pragma mark Drawing - (void)drawRect:(CGRect)rect diff --git a/Classes/ProgressViews/M13ProgressViewLetterpress.h b/Classes/ProgressViews/M13ProgressViewLetterpress.h index cf5169f..d70aa3f 100644 --- a/Classes/ProgressViews/M13ProgressViewLetterpress.h +++ b/Classes/ProgressViews/M13ProgressViewLetterpress.h @@ -24,7 +24,7 @@ typedef enum { */ @property (nonatomic, assign) M13ProgressViewLetterpressPointShape pointShape; /** - The amount of space between the grid points. + The amount of space between the grid points, as a percentage of the point's size. */ @property (nonatomic, assign) CGFloat pointSpacing; /** diff --git a/Classes/ProgressViews/M13ProgressViewLetterpress.m b/Classes/ProgressViews/M13ProgressViewLetterpress.m index 6e8ca78..0bbbfc4 100644 --- a/Classes/ProgressViews/M13ProgressViewLetterpress.m +++ b/Classes/ProgressViews/M13ProgressViewLetterpress.m @@ -108,7 +108,6 @@ - (void)setup _springDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(rotateWithDisplayLink:)]; [_springDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:(id)kCFRunLoopCommonModes]; - } - (void)setFrame:(CGRect)frame @@ -127,6 +126,12 @@ - (void)setNeedsDisplay [letterpressView setNeedsDisplay]; } +- (CGSize)intrinsicContentSize +{ + //Everything is based on scale. No minimum size. + return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric); +} + #pragma mark - Properties - (void)setNumberOfGridPoints:(CGPoint)numberOfGridPoints @@ -143,6 +148,11 @@ - (void)setPointShape:(M13ProgressViewLetterpressPointShape)pointShape - (void)setPointSpacing:(CGFloat)pointSpacing { + if (pointSpacing > 1) { + pointSpacing = 1; + } else if (pointSpacing < 0) { + pointSpacing = 0; + } _pointSpacing = pointSpacing; [self setNeedsDisplay]; } @@ -263,7 +273,7 @@ - (void)drawRect:(CGRect)rect //Calculat the rect of the point pointRect.size = pointSize; pointRect.origin = CGPointMake(pointSize.width * x, pointSize.height * y); - pointRect = CGRectInset(pointRect, _progressView.pointSpacing, _progressView.pointSpacing); + pointRect = CGRectInset(pointRect, pointSize.width * _progressView.pointSpacing, pointSize.height * _progressView.pointSpacing); //Set the fill color if (index < indexToFillTo) { @@ -285,4 +295,6 @@ - (void)drawRect:(CGRect)rect } } + + @end diff --git a/Classes/ProgressViews/M13ProgressViewMetro.m b/Classes/ProgressViews/M13ProgressViewMetro.m index 973a87c..b7572ef 100644 --- a/Classes/ProgressViews/M13ProgressViewMetro.m +++ b/Classes/ProgressViews/M13ProgressViewMetro.m @@ -213,6 +213,15 @@ - (void)setAnimationShape:(M13ProgressViewMetroAnimationShape)animationShape - (void)setNumberOfDots:(NSUInteger)numberOfDots { _numberOfDots = numberOfDots; + [self invalidateIntrinsicContentSize]; + [self stopAnimating]; + [self beginAnimating]; +} + +- (void)setDotSize:(CGSize)dotSize +{ + _dotSize = dotSize; + [self invalidateIntrinsicContentSize]; [self stopAnimating]; [self beginAnimating]; } @@ -285,7 +294,16 @@ - (void)showProgress } pastIndexToHighlightTo = indexToHighlightTo; } - +} + +- (CGSize)intrinsicContentSize +{ + //No real constraint on size. + if (_animationShape == M13ProgressViewMetroAnimationShapeEllipse || _animationShape == M13ProgressViewMetroAnimationShapeRectangle) { + return CGSizeMake(3 * _dotSize.width, 3 * _dotSize.height); + } else { + return CGSizeMake(_dotSize.width * _numberOfDots, _dotSize.height); + } } #pragma mark Animation diff --git a/Classes/ProgressViews/M13ProgressViewPie.m b/Classes/ProgressViews/M13ProgressViewPie.m index a8a0172..aba51d1 100644 --- a/Classes/ProgressViews/M13ProgressViewPie.m +++ b/Classes/ProgressViews/M13ProgressViewPie.m @@ -145,6 +145,7 @@ - (void)setBackgroundRingWidth:(CGFloat)backgroundRingWidth _backgroundLayer.lineWidth = _backgroundRingWidth; _backgroundRingWidthOverriden = YES; [self setNeedsDisplay]; + [self invalidateIntrinsicContentSize]; } #pragma mark Actions @@ -343,6 +344,16 @@ - (void)layoutSubviews [self setNeedsDisplay]; } +- (CGSize)intrinsicContentSize +{ + if (!_backgroundRingWidthOverriden) { + //Based on scale + return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric); + } else { + return CGSizeMake(2 * _backgroundRingWidth, 2 * _backgroundRingWidth); + } +} + - (void)setFrame:(CGRect)frame { //Keep the progress view square. diff --git a/Classes/ProgressViews/M13ProgressViewRadiative.m b/Classes/ProgressViews/M13ProgressViewRadiative.m index 4d1caed..c2b2a06 100644 --- a/Classes/ProgressViews/M13ProgressViewRadiative.m +++ b/Classes/ProgressViews/M13ProgressViewRadiative.m @@ -221,6 +221,12 @@ - (void)layoutSubviews } } +- (CGSize)intrinsicContentSize +{ + //The width and height should be set with constraints. Can't think of a good way to figure out the minimum size with the point and scale based size calculations. + return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric); +} + #pragma mark Drawing - (void)drawRect:(CGRect)rect diff --git a/Classes/ProgressViews/M13ProgressViewRing.m b/Classes/ProgressViews/M13ProgressViewRing.m index 1001b5e..ff85d43 100755 --- a/Classes/ProgressViews/M13ProgressViewRing.m +++ b/Classes/ProgressViews/M13ProgressViewRing.m @@ -376,6 +376,12 @@ - (void)setFrame:(CGRect)frame [super setFrame:frame]; } +- (CGSize)intrinsicContentSize +{ + //This progress view scales + return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric); +} + #pragma mark Drawing - (void)drawRect:(CGRect)rect diff --git a/Classes/ProgressViews/M13ProgressViewSegmentedBar.m b/Classes/ProgressViews/M13ProgressViewSegmentedBar.m index e130654..921425d 100644 --- a/Classes/ProgressViews/M13ProgressViewSegmentedBar.m +++ b/Classes/ProgressViews/M13ProgressViewSegmentedBar.m @@ -272,6 +272,11 @@ - (void)layoutSubviews } +- (CGSize)intrinsicContentSize +{ + return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric); +} + #pragma mark Drawing - (NSInteger)numberOfFullSegments diff --git a/Classes/ProgressViews/M13ProgressViewSegmentedRing.m b/Classes/ProgressViews/M13ProgressViewSegmentedRing.m index 1fe77c0..5141761 100644 --- a/Classes/ProgressViews/M13ProgressViewSegmentedRing.m +++ b/Classes/ProgressViews/M13ProgressViewSegmentedRing.m @@ -159,6 +159,7 @@ - (void)setProgressRingWidth:(CGFloat)progressRingWidth _progressRingWidthOverriden = YES; [self updateAngles]; [self setNeedsDisplay]; + [self invalidateIntrinsicContentSize]; } - (void)setShowPercentage:(BOOL)showPercentage @@ -391,6 +392,14 @@ - (void)layoutSubviews [self setNeedsDisplay]; } +- (CGSize)intrinsicContentSize +{ + //This might need a little more fine tuning. + CGFloat base = _progressRingWidth * 2; + + return CGSizeMake(base, base); +} + - (void)setFrame:(CGRect)frame { //Keep the progress view square. diff --git a/Classes/ProgressViews/M13ProgressViewStripedBar.m b/Classes/ProgressViews/M13ProgressViewStripedBar.m index 17eac1a..347f3c8 100644 --- a/Classes/ProgressViews/M13ProgressViewStripedBar.m +++ b/Classes/ProgressViews/M13ProgressViewStripedBar.m @@ -167,12 +167,14 @@ - (void)setCornerRadius:(CGFloat)cornerRadius - (void)setStripeWidth:(CGFloat)stripeWidth { _stripeWidth = stripeWidth; + [self invalidateIntrinsicContentSize]; [self setNeedsDisplay]; } - (void)setBorderWidth:(CGFloat)borderWidth { _borderWidth = borderWidth; + [self invalidateIntrinsicContentSize]; [self setNeedsDisplay]; } @@ -282,6 +284,15 @@ - (void)layoutSubviews [self drawStripes]; } +- (CGSize)intrinsicContentSize +{ + //Border + border to progress bar margin. + CGFloat base = (_borderWidth * 2) + (_borderWidth * 2) + 1; + //Add some stripes so we can see them. + CGFloat width = base + (2 * _stripeWidth); + return CGSizeMake(width, base); +} + #pragma mark Drawing - (void)drawRect:(CGRect)rect diff --git a/M13ProgressSuite.xcworkspace/xcuserdata/Brandon.xcuserdatad/UserInterfaceState.xcuserstate b/M13ProgressSuite.xcworkspace/xcuserdata/Brandon.xcuserdatad/UserInterfaceState.xcuserstate index 228315e..e7ea0cd 100644 Binary files a/M13ProgressSuite.xcworkspace/xcuserdata/Brandon.xcuserdatad/UserInterfaceState.xcuserstate and b/M13ProgressSuite.xcworkspace/xcuserdata/Brandon.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/M13ProgressSuite/LetterpressViewController.m b/M13ProgressSuite/LetterpressViewController.m index ba23a12..8dee442 100644 --- a/M13ProgressSuite/LetterpressViewController.m +++ b/M13ProgressSuite/LetterpressViewController.m @@ -59,7 +59,7 @@ - (void)pointShapeChanged:(id)sender _progressView.pointSpacing = 0.0; } else { _progressView.pointShape = M13ProgressViewLetterpressPointShapeSquare; - _progressView.pointSpacing = 2.0; + _progressView.pointSpacing = .15; } }