@@ -95,6 +95,7 @@ - (void)initialize
95
95
_numOfSubDivisions = kDefaultNumOfSubDivisions ;
96
96
97
97
// Ring
98
+ _showRingBackground = YES ;
98
99
_ringThickness = kDefaultRingThickness ;
99
100
_ringBackgroundColor = kDefaultRingBackgroundColor ;
100
101
@@ -165,11 +166,13 @@ - (void)drawRect:(CGRect)rect
165
166
/* !
166
167
* Draw the ring background
167
168
*/
168
- CGContextSetLineWidth (context, self.ringThickness );
169
- CGContextBeginPath (context);
170
- CGContextAddArc (context, center.x , center.y , ringRadius, 0 , M_PI * 2 , 0 );
171
- CGContextSetStrokeColorWithColor (context, [self .ringBackgroundColor colorWithAlphaComponent: 0.3 ].CGColor );
172
- CGContextStrokePath (context);
169
+ if (self.showRingBackground ) {
170
+ CGContextSetLineWidth (context, self.ringThickness );
171
+ CGContextBeginPath (context);
172
+ CGContextAddArc (context, center.x , center.y , ringRadius, 0 , M_PI * 2 , 0 );
173
+ CGContextSetStrokeColorWithColor (context, [self .ringBackgroundColor colorWithAlphaComponent: 0.3 ].CGColor );
174
+ CGContextStrokePath (context);
175
+ }
173
176
174
177
/* !
175
178
* Draw the ring progress background
@@ -264,10 +267,15 @@ - (void)drawRect:(CGRect)rect
264
267
self.valueLabel = [[UILabel alloc ] init ];
265
268
self.valueLabel .backgroundColor = [UIColor clearColor ];
266
269
self.valueLabel .textAlignment = NSTextAlignmentCenter;
267
- self.valueLabel .text = [NSString stringWithFormat: @" %0.f " , self .value];
270
+ if (self.decimalFormat ) {
271
+ self.valueLabel .text = [NSString stringWithFormat: @" %.1f " , self .value];
272
+ }
273
+ else {
274
+ self.valueLabel .text = [NSString stringWithFormat: @" %0.f " , self .value];
275
+ }
268
276
self.valueLabel .font = self.valueFont ;
269
277
self.valueLabel .adjustsFontSizeToFitWidth = YES ;
270
- self.valueLabel .minimumScaleFactor = 10 /self. valueLabel . font . pointSize ;
278
+ self.valueLabel .minimumScaleFactor = 0.5 ;
271
279
self.valueLabel .textColor = self.valueTextColor ;
272
280
[self addSubview: self .valueLabel];
273
281
}
@@ -288,7 +296,7 @@ - (void)drawRect:(CGRect)rect
288
296
}
289
297
self.minValueLabel .text = [NSString stringWithFormat: @" %0.f " , self .minValue];
290
298
self.minValueLabel .font = self.minMaxValueFont ;
291
- self.minValueLabel .minimumScaleFactor = 10 /self. minValueLabel . font . pointSize ;
299
+ self.minValueLabel .minimumScaleFactor = 0.5 ;
292
300
self.minValueLabel .textColor = self.minMaxValueTextColor ;
293
301
self.minValueLabel .hidden = !self.showMinMaxValue ;
294
302
CGPoint minDotCenter = CGPointMake (dotRadius * cos (self.startAngle ) + center.x , dotRadius * sin (self.startAngle ) + center.y );
@@ -307,7 +315,7 @@ - (void)drawRect:(CGRect)rect
307
315
}
308
316
self.maxValueLabel .text = [NSString stringWithFormat: @" %0.f " , self .maxValue];
309
317
self.maxValueLabel .font = self.minMaxValueFont ;
310
- self.maxValueLabel .minimumScaleFactor = 10 /self. maxValueLabel . font . pointSize ;
318
+ self.maxValueLabel .minimumScaleFactor = 0.5 ;
311
319
self.maxValueLabel .textColor = self.minMaxValueTextColor ;
312
320
self.maxValueLabel .hidden = !self.showMinMaxValue ;
313
321
CGPoint maxDotCenter = CGPointMake (dotRadius * cos (self.endAngle ) + center.x , dotRadius * sin (self.endAngle ) + center.y );
@@ -324,7 +332,7 @@ - (void)drawRect:(CGRect)rect
324
332
self.unitOfMeasurementLabel .text = self.unitOfMeasurement ;
325
333
self.unitOfMeasurementLabel .font = self.unitOfMeasurementFont ;
326
334
self.unitOfMeasurementLabel .adjustsFontSizeToFitWidth = YES ;
327
- self.unitOfMeasurementLabel .minimumScaleFactor = 10 /self. unitOfMeasurementLabel . font . pointSize ;
335
+ self.unitOfMeasurementLabel .minimumScaleFactor = 0.5 ;
328
336
self.unitOfMeasurementLabel .textColor = self.unitOfMeasurementTextColor ;
329
337
[self addSubview: self .unitOfMeasurementLabel];
330
338
self.unitOfMeasurementLabel .hidden = !self.showUnitOfMeasurement ;
@@ -367,7 +375,12 @@ - (void)setValue:(CGFloat)value
367
375
/* !
368
376
* Set text for value label
369
377
*/
370
- self.valueLabel .text = [NSString stringWithFormat: @" %0.f " , _value];
378
+ if (self.decimalFormat ) {
379
+ self.valueLabel .text = [NSString stringWithFormat: @" %.1f " , _value];
380
+ }
381
+ else {
382
+ self.valueLabel .text = [NSString stringWithFormat: @" %0.f " , _value];
383
+ }
371
384
372
385
/* !
373
386
* Trigger the stoke animation of ring layer.
@@ -516,7 +529,6 @@ - (void)setValueFont:(UIFont *)valueFont
516
529
_valueFont = valueFont;
517
530
518
531
self.valueLabel .font = _valueFont;
519
- self.valueLabel .minimumScaleFactor = 10 /_valueFont.pointSize ;
520
532
}
521
533
}
522
534
@@ -580,7 +592,6 @@ - (void)setUnitOfMeasurementFont:(UIFont *)unitOfMeasurementFont
580
592
_unitOfMeasurementFont = unitOfMeasurementFont;
581
593
582
594
self.unitOfMeasurementLabel .font = _unitOfMeasurementFont;
583
- self.unitOfMeasurementLabel .minimumScaleFactor = 10 /_unitOfMeasurementFont.pointSize ;
584
595
}
585
596
}
586
597
0 commit comments