Skip to content

Commit e90fead

Browse files
committed
Fixed Issue #34
Added Intrinsic content size for use with auto layout.
1 parent 98a2b35 commit e90fead

15 files changed

+119
-7
lines changed

Classes/ProgressViews/M13ProgressViewBar.m

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ - (void)setProgressBarThickness:(CGFloat)progressBarThickness
182182
[self setNeedsDisplay];
183183
//Update strokeWidth
184184
_progressLayer.lineWidth = progressBarThickness;
185-
//Update the corner radius
186-
185+
[self invalidateIntrinsicContentSize];
187186
}
188187

189188
#pragma mark Actions
@@ -534,6 +533,26 @@ - (void)layoutSubviews
534533

535534
}
536535

536+
- (CGSize)intrinsicContentSize
537+
{
538+
CGFloat labelProgressBufferDistance = _progressBarThickness * 4;
539+
540+
//Progress bar thickness is the only non-scale based size parameter.
541+
if (_progressDirection == M13ProgressViewBarProgressDirectionBottomToTop || _progressDirection == M13ProgressViewBarProgressDirectionTopToBottom) {
542+
if (_percentagePosition == M13ProgressViewBarPercentagePositionTop || _percentagePosition == M13ProgressViewBarPercentagePositionBottom) {
543+
return CGSizeMake(_progressBarThickness, labelProgressBufferDistance);
544+
} else {
545+
return CGSizeMake(_progressBarThickness + labelProgressBufferDistance, UIViewNoIntrinsicMetric);
546+
}
547+
} else {
548+
if (_percentagePosition == M13ProgressViewBarPercentagePositionTop || _percentagePosition == M13ProgressViewBarPercentagePositionBottom) {
549+
return CGSizeMake(UIViewNoIntrinsicMetric, _progressBarThickness + labelProgressBufferDistance);
550+
} else {
551+
return CGSizeMake(labelProgressBufferDistance, _progressBarThickness);
552+
}
553+
}
554+
}
555+
537556
- (CGFloat)maximumFontSizeThatFitsInRect:(CGRect)frame
538557
{
539558
//Starting parameters

Classes/ProgressViews/M13ProgressViewBorderedBar.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ - (void)layoutSubviews
347347
}
348348
}
349349

350+
- (CGSize)intrinsicContentSize
351+
{
352+
return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric);
353+
}
354+
350355
#pragma mark Drawing
351356

352357
- (void)drawRect:(CGRect)rect

Classes/ProgressViews/M13ProgressViewFilteredImage.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ - (void)layoutSubviews
161161
_progressView.frame = self.bounds;
162162
}
163163

164+
- (CGSize)intrinsicContentSize
165+
{
166+
return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric);
167+
}
168+
164169
#pragma mark Drawing
165170

166171
- (void)drawRect:(CGRect)rect

Classes/ProgressViews/M13ProgressViewImage.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ - (void)layoutSubviews
170170
_progressView.frame = self.bounds;
171171
}
172172

173+
- (CGSize)intrinsicContentSize
174+
{
175+
return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric);
176+
}
177+
173178
#pragma mark Drawing
174179

175180
- (void)drawRect:(CGRect)rect

Classes/ProgressViews/M13ProgressViewLetterpress.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typedef enum {
2424
*/
2525
@property (nonatomic, assign) M13ProgressViewLetterpressPointShape pointShape;
2626
/**
27-
The amount of space between the grid points.
27+
The amount of space between the grid points, as a percentage of the point's size.
2828
*/
2929
@property (nonatomic, assign) CGFloat pointSpacing;
3030
/**

Classes/ProgressViews/M13ProgressViewLetterpress.m

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ - (void)setup
108108
_springDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(rotateWithDisplayLink:)];
109109
[_springDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:(id)kCFRunLoopCommonModes];
110110

111-
112111
}
113112

114113
- (void)setFrame:(CGRect)frame
@@ -127,6 +126,12 @@ - (void)setNeedsDisplay
127126
[letterpressView setNeedsDisplay];
128127
}
129128

129+
- (CGSize)intrinsicContentSize
130+
{
131+
//Everything is based on scale. No minimum size.
132+
return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric);
133+
}
134+
130135
#pragma mark - Properties
131136

132137
- (void)setNumberOfGridPoints:(CGPoint)numberOfGridPoints
@@ -143,6 +148,11 @@ - (void)setPointShape:(M13ProgressViewLetterpressPointShape)pointShape
143148

144149
- (void)setPointSpacing:(CGFloat)pointSpacing
145150
{
151+
if (pointSpacing > 1) {
152+
pointSpacing = 1;
153+
} else if (pointSpacing < 0) {
154+
pointSpacing = 0;
155+
}
146156
_pointSpacing = pointSpacing;
147157
[self setNeedsDisplay];
148158
}
@@ -263,7 +273,7 @@ - (void)drawRect:(CGRect)rect
263273
//Calculat the rect of the point
264274
pointRect.size = pointSize;
265275
pointRect.origin = CGPointMake(pointSize.width * x, pointSize.height * y);
266-
pointRect = CGRectInset(pointRect, _progressView.pointSpacing, _progressView.pointSpacing);
276+
pointRect = CGRectInset(pointRect, pointSize.width * _progressView.pointSpacing, pointSize.height * _progressView.pointSpacing);
267277

268278
//Set the fill color
269279
if (index < indexToFillTo) {
@@ -285,4 +295,6 @@ - (void)drawRect:(CGRect)rect
285295
}
286296
}
287297

298+
299+
288300
@end

Classes/ProgressViews/M13ProgressViewMetro.m

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ - (void)setAnimationShape:(M13ProgressViewMetroAnimationShape)animationShape
213213
- (void)setNumberOfDots:(NSUInteger)numberOfDots
214214
{
215215
_numberOfDots = numberOfDots;
216+
[self invalidateIntrinsicContentSize];
217+
[self stopAnimating];
218+
[self beginAnimating];
219+
}
220+
221+
- (void)setDotSize:(CGSize)dotSize
222+
{
223+
_dotSize = dotSize;
224+
[self invalidateIntrinsicContentSize];
216225
[self stopAnimating];
217226
[self beginAnimating];
218227
}
@@ -285,7 +294,16 @@ - (void)showProgress
285294
}
286295
pastIndexToHighlightTo = indexToHighlightTo;
287296
}
288-
297+
}
298+
299+
- (CGSize)intrinsicContentSize
300+
{
301+
//No real constraint on size.
302+
if (_animationShape == M13ProgressViewMetroAnimationShapeEllipse || _animationShape == M13ProgressViewMetroAnimationShapeRectangle) {
303+
return CGSizeMake(3 * _dotSize.width, 3 * _dotSize.height);
304+
} else {
305+
return CGSizeMake(_dotSize.width * _numberOfDots, _dotSize.height);
306+
}
289307
}
290308

291309
#pragma mark Animation

Classes/ProgressViews/M13ProgressViewPie.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ - (void)setBackgroundRingWidth:(CGFloat)backgroundRingWidth
145145
_backgroundLayer.lineWidth = _backgroundRingWidth;
146146
_backgroundRingWidthOverriden = YES;
147147
[self setNeedsDisplay];
148+
[self invalidateIntrinsicContentSize];
148149
}
149150

150151
#pragma mark Actions
@@ -343,6 +344,16 @@ - (void)layoutSubviews
343344
[self setNeedsDisplay];
344345
}
345346

347+
- (CGSize)intrinsicContentSize
348+
{
349+
if (!_backgroundRingWidthOverriden) {
350+
//Based on scale
351+
return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric);
352+
} else {
353+
return CGSizeMake(2 * _backgroundRingWidth, 2 * _backgroundRingWidth);
354+
}
355+
}
356+
346357
- (void)setFrame:(CGRect)frame
347358
{
348359
//Keep the progress view square.

Classes/ProgressViews/M13ProgressViewRadiative.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ - (void)layoutSubviews
221221
}
222222
}
223223

224+
- (CGSize)intrinsicContentSize
225+
{
226+
//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.
227+
return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric);
228+
}
229+
224230
#pragma mark Drawing
225231

226232
- (void)drawRect:(CGRect)rect

Classes/ProgressViews/M13ProgressViewRing.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ - (void)setFrame:(CGRect)frame
376376
[super setFrame:frame];
377377
}
378378

379+
- (CGSize)intrinsicContentSize
380+
{
381+
//This progress view scales
382+
return CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric);
383+
}
384+
379385
#pragma mark Drawing
380386

381387
- (void)drawRect:(CGRect)rect

0 commit comments

Comments
 (0)