-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHLProgressView.m
executable file
·664 lines (541 loc) · 21 KB
/
HLProgressView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
//
// HLProgressView.m
// HLProgressViewDemo
//
// Created by MrUncle on 15/3/3.
// Copyright © 2015年 MrUncle. All rights reserved.
//
#import "HLProgressView.h"
// Sizes
const NSInteger HLProgressViewDefaultSizeInset = 1; //px
// Animation times
const NSTimeInterval HLProgressViewStripesAnimationTime = 1.0f / 30.0f; // s
// Font name
static NSString * HLProgressViewDefaultName = @"Arial-BoldMT";
// Default progress value
const CGFloat HLProgressViewDefaultProgress = 0.3f;
@interface HLProgressView ()
@property (nonatomic, assign) double stripesOffset;
@property (nonatomic, assign) CGFloat internalCornerRadius;
@property (nonatomic, strong) NSTimer *stripesTimer;
@property (nonatomic, strong) NSArray *colors;
@property (nonatomic, strong) NSTimer *progressTargetTimer;
@property (nonatomic, assign) CGFloat progressTargetValue;
/** Init the progress bar with the default values. */
- (void)initializeProgressBar;
/** Build the stripes using the given parameters. */
- (UIBezierPath *)stripeWithOrigin:(CGPoint)origin bounds:(CGRect)frame orientation:(HLProgressViewStripesOrientation)orientation;
/** Draw the background (track) of the slider. */
- (void)drawTrack:(CGContextRef)context withRect:(CGRect)rect;
/** Draw the progress bar. */
- (void)drawProgressBar:(CGContextRef)context withInnerRect:(CGRect)innerRect outterRect:(CGRect)outterRect;
/** Draw the gloss into the given rect. */
- (void)drawGloss:(CGContextRef)context withRect:(CGRect)rect;
/** Draw the stipes into the given rect. */
- (void)drawStripes:(CGContextRef)context withRect:(CGRect)rect;
/** Draw the given text into the given location of the rect. */
- (void)drawText:(CGContextRef)context withRect:(CGRect)rect;
/** Callback for the setProgress:Animated: animation timer. */
- (void)updateProgressWithTimer:(NSTimer *)timer;
@end
@implementation HLProgressView
@synthesize progress = _progress;
- (void)dealloc
{
if (_stripesTimer && [_stripesTimer isValid])
{
[_stripesTimer invalidate];
}
if (_progressTargetTimer && [_progressTargetTimer isValid])
{
[_progressTargetTimer invalidate];
}
[self removeObserver:self forKeyPath:@"stripesAnimated"];
[self removeObserver:self forKeyPath:@"hideStripes"];
}
- (id)initWithFrame:(CGRect)frameRect
{
if ((self = [super initWithFrame:frameRect]))
{
[self initializeProgressBar];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
if ((self = [super initWithCoder:aDecoder]))
{
[self initializeProgressBar];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGFloat height = CGRectGetHeight(self.bounds) - CGRectGetHeight(self.bounds) / 3;
_indicatorTextLabel.font = [UIFont fontWithName:HLProgressViewDefaultName size: height];
}
- (void)drawRect:(CGRect)rect
{
if (self.isHidden)
{
return;
}
CGContextRef context = UIGraphicsGetCurrentContext();
// Refresh the corner radius value
self.internalCornerRadius = 0;
if (_type == HLProgressViewTypeRounded) {
if (_cornerRadius > 0) {
self.internalCornerRadius = _cornerRadius;
}
else {
self.internalCornerRadius = rect.size.height / 2;
}
}
// Compute the progressOffset for the stripe's animation
self.stripesOffset = (!_stripesAnimated || fabs(self.stripesOffset) > 2 * _stripesWidth - 1) ? 0 : self.stripesDirection * fabs(self.stripesAnimationVelocity) + self.stripesOffset;
// Draw the background track
if (!_hideTrack)
{
[self drawTrack:context withRect:rect];
}
// Draw the indicator text if necessary
if (_indicatorTextDisplayMode == HLProgressViewIndicatorTextDisplayModeTrack)
{
[self drawText:context withRect:rect];
}
// Compute the inner rectangle
CGRect innerRect;
if (_type == HLProgressViewTypeRounded)
{
innerRect = CGRectMake(_progressBarInset,
_progressBarInset,
CGRectGetWidth(rect) * self.progress - 2 * _progressBarInset,
CGRectGetHeight(rect) - 2 * _progressBarInset);
} else
{
innerRect = CGRectMake(0, 0, CGRectGetWidth(rect) * self.progress, CGRectGetHeight(rect));
}
if (self.progress == 0 && _behavior == HLProgressViewBehaviorIndeterminate)
{
[self drawStripes:context withRect:rect];
} else if (self.progress > 0)
{
[self drawProgressBar:context withInnerRect:innerRect outterRect:rect];
if (_stripesWidth > 0 && !_hideStripes)
{
if (_behavior == HLProgressViewBehaviorWaiting)
{
if (self.progress == 1.0f)
{
[self drawStripes:context withRect:innerRect];
}
} else if (_behavior != HLProgressViewBehaviorIndeterminate)
{
[self drawStripes:context withRect:innerRect];
}
}
if (!_hideGloss)
{
[self drawGloss:context withRect:innerRect];
}
// Draw the indicator text if necessary
if (_indicatorTextDisplayMode == HLProgressViewIndicatorTextDisplayModeProgress)
{
[self drawText:context withRect:innerRect];
}
}
}
#pragma mark - Properties
- (void)setType:(HLProgressViewType)type {
_type = type;
switch (type) {
case HLProgressViewTypeRounded:
_hideGloss = NO;
break;
default:
_hideGloss = YES;
break;
}
}
- (void)setProgressBarProgressTime:(NSTimeInterval)progressBarProgressTime{
_progressBarProgressTime = progressBarProgressTime;
}
- (CGFloat)progress
{
@synchronized (self)
{
return _progress;
}
}
- (void)setProgress:(CGFloat)progress
{
[self setProgress:progress animated:NO];
}
- (void)setBehavior:(HLProgressViewBehavior)behavior
{
_behavior = behavior;
[self setNeedsDisplay];
}
- (void)setProgressTintColor:(UIColor *)progressTintColor
{
progressTintColor = (progressTintColor) ? progressTintColor : [UIColor blueColor];
const CGFloat *c = CGColorGetComponents(progressTintColor.CGColor);
UIColor *leftColor = [UIColor colorWithRed:(c[0] / 2.0f) green:(c[1] / 2.0f) blue:(c[2] / 2.0f) alpha:(c[3])];
UIColor *rightColor = progressTintColor;
NSArray *colors = @[leftColor, rightColor];
[self setProgressTintColors:colors];
}
- (void)setProgressTintColors:(NSArray *)progressTintColors
{
NSAssert(progressTintColors, @"progressTintColors must not be null");
NSAssert([progressTintColors count], @"progressTintColors must contain at least one element");
if (_progressTintColors != progressTintColors)
{
_progressTintColors = progressTintColors;
}
NSMutableArray *colors = [NSMutableArray arrayWithCapacity:[progressTintColors count]];
for (UIColor *color in progressTintColors)
{
[colors addObject:(id)color.CGColor];
}
self.colors = colors;
}
#pragma mark - Public Methods
- (void)setProgress:(CGFloat)progress animated:(BOOL)animated
{
@synchronized (self)
{
if (_progressTargetTimer && [_progressTargetTimer isValid])
{
[_progressTargetTimer invalidate];
}
CGFloat newProgress = progress;
if (newProgress > 1.0f)
{
newProgress = 1.0f;
} else if (newProgress < 0.0f)
{
newProgress = 0.0f;
}
if (animated)
{
_progressTargetValue = newProgress;
CGFloat incrementValue = ((_progressTargetValue - _progress) * HLProgressViewStripesAnimationTime) / _progressBarProgressTime;
self.progressTargetTimer = [NSTimer timerWithTimeInterval:HLProgressViewStripesAnimationTime
target:self
selector:@selector(updateProgressWithTimer:)
userInfo:[NSNumber numberWithFloat:incrementValue]
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_progressTargetTimer forMode:NSRunLoopCommonModes];
} else
{
_progress = newProgress;
[self setNeedsDisplay];
}
}
}
#pragma mark - Private Methods
- (void)updateProgressWithTimer:(NSTimer *)timer
{
CGFloat dt_progress = [timer.userInfo floatValue];
_progress += dt_progress;
if ((dt_progress < 0 && _progress <= _progressTargetValue)
|| (dt_progress > 0 && _progress >= _progressTargetValue))
{
[_progressTargetTimer invalidate];
_progressTargetTimer = nil;
_progress = _progressTargetValue;
}
[self setNeedsDisplay];
}
- (void)initializeProgressBar
{
[self addObserver:self forKeyPath:@"hideStripes" options:NSKeyValueObservingOptionNew context:nil];
[self addObserver:self forKeyPath:@"stripesAnimated" options:NSKeyValueObservingOptionNew context:nil];
_type = HLProgressViewTypeRounded;
_progressStretch = YES;
_hideGloss = NO;
_progress = HLProgressViewDefaultProgress;
_hideStripes = NO;
_hideTrack = NO;
_behavior = HLProgressViewBehaviorDefault;
_stripesColor = [UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:0.28f];
_cornerRadius = 0;
_progressBarProgressTime = 1;
_indicatorTextLabel = [[UILabel alloc] initWithFrame:self.frame];
_indicatorTextLabel.adjustsFontSizeToFitWidth = YES;
_indicatorTextLabel.backgroundColor = [UIColor clearColor];
_indicatorTextLabel.textAlignment = NSTextAlignmentRight;
_indicatorTextLabel.lineBreakMode = NSLineBreakByTruncatingHead;
_indicatorTextLabel.textColor = [UIColor clearColor];
_indicatorTextLabel.minimumScaleFactor = 3;
_indicatorTextDisplayMode = HLProgressViewIndicatorTextDisplayModeNone;
self.trackTintColor = [UIColor blackColor];
self.progressTintColor = self.backgroundColor;
self.stripesOffset = 0;
self.stripesTimer = nil;
self.stripesAnimated = YES;
self.stripesOrientation = HLProgressViewStripesOrientationRight;
self.stripesDirection = HLProgressViewStripesDirectionRight;
self.stripesAnimationVelocity = 1;
self.stripesWidth = HLProgressViewDefaultStripeWidth;
self.stripesDelta = HLProgressViewDefaultStripeDelta;
self.progressBarInset = HLProgressViewDefaultSizeInset;
self.backgroundColor = [UIColor clearColor];
}
- (UIBezierPath *)stripeWithOrigin:(CGPoint)origin bounds:(CGRect)frame orientation:(HLProgressViewStripesOrientation)orientation
{
CGFloat height = CGRectGetHeight(frame);
UIBezierPath *rect = [UIBezierPath bezierPath];
[rect moveToPoint:origin];
switch (orientation)
{
case HLProgressViewStripesOrientationRight:
[rect addLineToPoint:CGPointMake(origin.x + _stripesWidth, origin.y)];
[rect addLineToPoint:CGPointMake(origin.x + _stripesWidth - _stripesDelta, origin.y + height)];
[rect addLineToPoint:CGPointMake(origin.x - _stripesDelta, origin.y + height)];
break;
case HLProgressViewStripesOrientationLeft:
[rect addLineToPoint:CGPointMake(origin.x - _stripesWidth, origin.y)];
[rect addLineToPoint:CGPointMake(origin.x - _stripesWidth + _stripesDelta, origin.y + height)];
[rect addLineToPoint:CGPointMake(origin.x + _stripesDelta, origin.y + height)];
break;
default:
[rect addLineToPoint:CGPointMake(origin.x - _stripesWidth, origin.y)];
[rect addLineToPoint:CGPointMake(origin.x - _stripesWidth, origin.y + height)];
[rect addLineToPoint:CGPointMake(origin.x, origin.y + height)];
break;
}
[rect addLineToPoint:origin];
[rect closePath];
return rect;
}
- (void)drawTrack:(CGContextRef)context withRect:(CGRect)rect
{
// Define the progress bar pattern to clip all the content inside
UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, CGRectGetWidth(rect), CGRectGetHeight(rect))
cornerRadius:_internalCornerRadius];
[roundedRect addClip];
CGContextSaveGState(context);
{
CGFloat trackWidth = CGRectGetWidth(rect);
CGFloat trackHeight = CGRectGetHeight(rect);
if (_type == HLProgressViewTypeRounded && !_hideGloss)
{
trackHeight -= 1;
trackWidth -= 1;
}
// Draw the track
UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, trackWidth, trackHeight) cornerRadius:_internalCornerRadius];
[_trackTintColor set];
[roundedRect fill];
if (_type == HLProgressViewTypeRounded)
{
// Draw the white shadow
[[UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:0.2] set];
UIBezierPath *shadow = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0.5f, 0, trackWidth, trackHeight)
cornerRadius:_internalCornerRadius];
[shadow stroke];
if (!_hideGloss)
{
// Draw the inner glow
[[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4f] set];
UIBezierPath *glow = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(_internalCornerRadius, 0, CGRectGetWidth(rect) - _internalCornerRadius * 2, 1)
cornerRadius:0];
[glow stroke];
}
}
}
CGContextRestoreGState(context);
}
- (void)drawProgressBar:(CGContextRef)context withInnerRect:(CGRect)innerRect outterRect:(CGRect)outterRect
{
CGRect gradientRect = _progressStretch ? innerRect : outterRect;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextSaveGState(context);
{
UIBezierPath *progressBounds = [UIBezierPath bezierPathWithRoundedRect:innerRect cornerRadius:_internalCornerRadius];
CGContextAddPath(context, [progressBounds CGPath]);
CGContextClip(context);
CFArrayRef colorRefs = (__bridge CFArrayRef)_colors;
NSUInteger colorCount = [_colors count];
CGFloat delta = 1.0f / [_colors count];
CGFloat semi_delta = delta / 2.0f;
CGFloat locations[colorCount];
for (NSInteger i = 0; i < colorCount; i++)
{
locations[i] = delta * i + semi_delta;
}
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, colorRefs, locations);
CGContextDrawLinearGradient(context, gradient, CGPointMake(CGRectGetMinX(gradientRect), CGRectGetMinY(gradientRect)), CGPointMake(CGRectGetMinX(gradientRect) + CGRectGetWidth(gradientRect), CGRectGetMinY(gradientRect)), (kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation));
CGGradientRelease(gradient);
}
CGContextRestoreGState(context);
CGColorSpaceRelease(colorSpace);
}
- (void)drawGloss:(CGContextRef)context withRect:(CGRect)rect
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextSaveGState(context);
{
CGRect fillRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, floorf(rect.size.height / 3));
// Draw the gloss
CGContextSetBlendMode(context, kCGBlendModeOverlay);
CGContextBeginTransparencyLayerWithRect(context, fillRect, NULL);
{
const CGFloat glossGradientComponents[] = {1.0f, 1.0f, 1.0f, 0.16f, 1.0f, 1.0f, 1.0f, 0.16f};
const CGGradientRef glossGradient = CGGradientCreateWithColorComponents(colorSpace, glossGradientComponents, NULL, (kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation));
CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));
CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect));
CGContextDrawLinearGradient(context, glossGradient, startPoint, endPoint, 0);
CGGradientRelease(glossGradient);
}
CGContextEndTransparencyLayer(context);
// Draw the gloss's drop shadow
CGContextSetBlendMode(context, kCGBlendModeSoftLight);
CGContextBeginTransparencyLayer(context, NULL);
{
const CGFloat glossDropShadowComponents[] = {0.0f, 0.0f, 0.0f, 0.16f, 0.0f, 0.0f, 0.0f, 0.0f};
CGColorRef glossDropShadowColor = CGColorCreate(colorSpace, glossDropShadowComponents);
CGContextSaveGState(context);
{
CGContextSetShadowWithColor(context, CGSizeMake(0, -1), 4, glossDropShadowColor);
CGContextFillRect(context, fillRect);
CGColorRelease(glossDropShadowColor);
}
CGContextRestoreGState(context);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextFillRect(context, fillRect);
}
CGContextEndTransparencyLayer(context);
}
CGContextRestoreGState(context);
// Draw progress bar glow
CGContextSaveGState(context);
{
UIBezierPath *progressBounds = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:_internalCornerRadius];
CGContextAddPath(context, [progressBounds CGPath]);
const CGFloat progressBarGlowComponents[] = {1.0f, 1.0f, 1.0f, 0.16f};
CGColorRef progressBarGlowColor = CGColorCreate(colorSpace, progressBarGlowComponents);
CGContextSetBlendMode(context, kCGBlendModeOverlay);
CGContextSetStrokeColorWithColor(context, progressBarGlowColor);
CGContextSetLineWidth(context, 2.0f);
CGContextStrokePath(context);
CGColorRelease(progressBarGlowColor);
}
CGContextRestoreGState(context);
CGColorSpaceRelease(colorSpace);
}
- (void)drawStripes:(CGContextRef)context withRect:(CGRect)rect
{
if (_stripesWidth == 0) {
return;
}
CGContextSaveGState(context);
{
UIBezierPath *allStripes = [UIBezierPath bezierPath];
NSInteger start = -_stripesWidth;
NSInteger end = rect.size.width / (2 * _stripesWidth) + (2 * _stripesWidth);
CGFloat yOffset = (_type == HLProgressViewTypeRounded) ? _progressBarInset : 0;
for (NSInteger i = start; i <= end; i++)
{
UIBezierPath *stripe = [self stripeWithOrigin:CGPointMake(i * 2 * _stripesWidth + _stripesOffset, yOffset)
bounds:rect
orientation:_stripesOrientation];
[allStripes appendPath:stripe];
}
// Clip the progress frame
UIBezierPath *clipPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:_internalCornerRadius];
CGContextAddPath(context, [clipPath CGPath]);
CGContextClip(context);
CGContextSaveGState(context);
{
// Clip the stripes
CGContextAddPath(context, [allStripes CGPath]);
CGContextClip(context);
CGContextSetFillColorWithColor(context, [_stripesColor CGColor]);
CGContextFillRect(context, rect);
}
CGContextRestoreGState(context);
}
CGContextRestoreGState(context);
}
- (void)drawText:(CGContextRef)context withRect:(CGRect)rect
{
if (_indicatorTextLabel == nil)
{
return;
}
CGRect innerRect = CGRectInset(rect, 4, 2);
_indicatorTextLabel.frame = innerRect;
NSString *indicatorText = _indicatorTextLabel.text;
BOOL hasText = (_indicatorTextLabel.text != nil);
if (!hasText)
{
indicatorText = [NSString stringWithFormat:@"%.0f%%", (self.progress * 100)];
}
CGRect textRect;
if ([indicatorText respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)])
{
textRect = [indicatorText boundingRectWithSize:CGRectInset(innerRect, 20, 0).size
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{ NSFontAttributeName: _indicatorTextLabel.font }
context:nil];
}
if (innerRect.size.width < textRect.size.width || innerRect.size.height + 4 < textRect.size.height)
{
return;
}
_indicatorTextLabel.text = indicatorText;
BOOL hasTextColor = ![_indicatorTextLabel.textColor isEqual:[UIColor clearColor]];
if (!hasTextColor)
{
CGColorRef backgroundColor = nil;
if (_indicatorTextDisplayMode == HLProgressViewIndicatorTextDisplayModeTrack)
{
backgroundColor = _trackTintColor.CGColor ?: [UIColor blackColor].CGColor;
} else
{
backgroundColor = (__bridge CGColorRef)[_colors lastObject];
}
const CGFloat *components = CGColorGetComponents(backgroundColor);
BOOL isLightBackground = (components[0] + components[1] + components[2]) / 3.0f >= 0.5f;
_indicatorTextLabel.textColor = (isLightBackground) ? [UIColor blackColor] : [UIColor whiteColor];
}
[_indicatorTextLabel drawTextInRect:innerRect];
if (!hasTextColor)
{
_indicatorTextLabel.textColor = [UIColor clearColor];
}
if (!hasText)
{
_indicatorTextLabel.text = nil;
}
}
#pragma mark - KVO Delegate Methods
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"hideStripes"] || [keyPath isEqualToString:@"stripesAnimated"])
{
if (!_hideStripes && _stripesAnimated)
{
if (_stripesTimer == nil)
{
_stripesTimer= [NSTimer timerWithTimeInterval:HLProgressViewStripesAnimationTime
target:self
selector:@selector(setNeedsDisplay)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_stripesTimer forMode:NSRunLoopCommonModes];
}
} else
{
if (_stripesTimer && [_stripesTimer isValid])
{
[_stripesTimer invalidate];
}
self.stripesTimer = nil;
}
}
}
@end