Skip to content

Commit

Permalink
Fixed Issue #34
Browse files Browse the repository at this point in the history
Added Intrinsic content size for use with auto layout.
  • Loading branch information
Marxon13 committed Jul 17, 2014
1 parent 98a2b35 commit e90fead
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 7 deletions.
23 changes: 21 additions & 2 deletions Classes/ProgressViews/M13ProgressViewBar.m
Expand Up @@ -182,8 +182,7 @@ - (void)setProgressBarThickness:(CGFloat)progressBarThickness
[self setNeedsDisplay];
//Update strokeWidth
_progressLayer.lineWidth = progressBarThickness;
//Update the corner radius

[self invalidateIntrinsicContentSize];
}

#pragma mark Actions
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Classes/ProgressViews/M13ProgressViewBorderedBar.m
Expand Up @@ -347,6 +347,11 @@ - (void)layoutSubviews
}
}

- (CGSize)intrinsicContentSize
{
return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric);
}

#pragma mark Drawing

- (void)drawRect:(CGRect)rect
Expand Down
5 changes: 5 additions & 0 deletions Classes/ProgressViews/M13ProgressViewFilteredImage.m
Expand Up @@ -161,6 +161,11 @@ - (void)layoutSubviews
_progressView.frame = self.bounds;
}

- (CGSize)intrinsicContentSize
{
return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric);
}

#pragma mark Drawing

- (void)drawRect:(CGRect)rect
Expand Down
5 changes: 5 additions & 0 deletions Classes/ProgressViews/M13ProgressViewImage.m
Expand Up @@ -170,6 +170,11 @@ - (void)layoutSubviews
_progressView.frame = self.bounds;
}

- (CGSize)intrinsicContentSize
{
return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric);
}

#pragma mark Drawing

- (void)drawRect:(CGRect)rect
Expand Down
2 changes: 1 addition & 1 deletion Classes/ProgressViews/M13ProgressViewLetterpress.h
Expand Up @@ -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;
/**
Expand Down
16 changes: 14 additions & 2 deletions Classes/ProgressViews/M13ProgressViewLetterpress.m
Expand Up @@ -108,7 +108,6 @@ - (void)setup
_springDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(rotateWithDisplayLink:)];
[_springDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:(id)kCFRunLoopCommonModes];


}

- (void)setFrame:(CGRect)frame
Expand All @@ -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
Expand All @@ -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];
}
Expand Down Expand Up @@ -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) {
Expand All @@ -285,4 +295,6 @@ - (void)drawRect:(CGRect)rect
}
}



@end
20 changes: 19 additions & 1 deletion Classes/ProgressViews/M13ProgressViewMetro.m
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions Classes/ProgressViews/M13ProgressViewPie.m
Expand Up @@ -145,6 +145,7 @@ - (void)setBackgroundRingWidth:(CGFloat)backgroundRingWidth
_backgroundLayer.lineWidth = _backgroundRingWidth;
_backgroundRingWidthOverriden = YES;
[self setNeedsDisplay];
[self invalidateIntrinsicContentSize];
}

#pragma mark Actions
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions Classes/ProgressViews/M13ProgressViewRadiative.m
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Classes/ProgressViews/M13ProgressViewRing.m
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Classes/ProgressViews/M13ProgressViewSegmentedBar.m
Expand Up @@ -272,6 +272,11 @@ - (void)layoutSubviews

}

- (CGSize)intrinsicContentSize
{
return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric);
}

#pragma mark Drawing

- (NSInteger)numberOfFullSegments
Expand Down
9 changes: 9 additions & 0 deletions Classes/ProgressViews/M13ProgressViewSegmentedRing.m
Expand Up @@ -159,6 +159,7 @@ - (void)setProgressRingWidth:(CGFloat)progressRingWidth
_progressRingWidthOverriden = YES;
[self updateAngles];
[self setNeedsDisplay];
[self invalidateIntrinsicContentSize];
}

- (void)setShowPercentage:(BOOL)showPercentage
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions Classes/ProgressViews/M13ProgressViewStripedBar.m
Expand Up @@ -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];
}

Expand Down Expand Up @@ -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
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion M13ProgressSuite/LetterpressViewController.m
Expand Up @@ -59,7 +59,7 @@ - (void)pointShapeChanged:(id)sender
_progressView.pointSpacing = 0.0;
} else {
_progressView.pointShape = M13ProgressViewLetterpressPointShapeSquare;
_progressView.pointSpacing = 2.0;
_progressView.pointSpacing = .15;
}
}

Expand Down

0 comments on commit e90fead

Please sign in to comment.