Skip to content

Commit aa8f9b0

Browse files
committed
Support decimal format
1 parent f2e7364 commit aa8f9b0

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

LMGaugeView.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "LMGaugeView"
4-
s.version = "1.0.4"
4+
s.version = "1.0.5"
55
s.summary = "LMGaugeView is a simple and customizable gauge control for iOS."
66
s.homepage = "https://github.com/lminhtm/LMGaugeView"
77
s.license = 'MIT'

LMGaugeView/LMGaugeView.h

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ IB_DESIGNABLE
4848
*/
4949
@property (nonatomic, assign) IBInspectable CGFloat ringThickness;
5050

51+
/*!
52+
* A boolean indicates whether to show ring background.
53+
*/
54+
@property (nonatomic, assign) IBInspectable BOOL showRingBackground;
55+
5156
/*!
5257
* The background color of the ring.
5358
*/
@@ -138,6 +143,11 @@ IB_DESIGNABLE
138143
*/
139144
@property (nonatomic, strong) IBInspectable UIColor *unitOfMeasurementTextColor;
140145

146+
/*!
147+
* A boolean indicates whether to show decimal value.
148+
*/
149+
@property (nonatomic, assign) IBInspectable BOOL decimalFormat;
150+
141151
/*!
142152
* The receiver of all gauge view delegate callbacks.
143153
*/

LMGaugeView/LMGaugeView.m

+24-13
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ - (void)initialize
9595
_numOfSubDivisions = kDefaultNumOfSubDivisions;
9696

9797
// Ring
98+
_showRingBackground = YES;
9899
_ringThickness = kDefaultRingThickness;
99100
_ringBackgroundColor = kDefaultRingBackgroundColor;
100101

@@ -165,11 +166,13 @@ - (void)drawRect:(CGRect)rect
165166
/*!
166167
* Draw the ring background
167168
*/
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+
}
173176

174177
/*!
175178
* Draw the ring progress background
@@ -264,10 +267,15 @@ - (void)drawRect:(CGRect)rect
264267
self.valueLabel = [[UILabel alloc] init];
265268
self.valueLabel.backgroundColor = [UIColor clearColor];
266269
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+
}
268276
self.valueLabel.font = self.valueFont;
269277
self.valueLabel.adjustsFontSizeToFitWidth = YES;
270-
self.valueLabel.minimumScaleFactor = 10/self.valueLabel.font.pointSize;
278+
self.valueLabel.minimumScaleFactor = 0.5;
271279
self.valueLabel.textColor = self.valueTextColor;
272280
[self addSubview:self.valueLabel];
273281
}
@@ -288,7 +296,7 @@ - (void)drawRect:(CGRect)rect
288296
}
289297
self.minValueLabel.text = [NSString stringWithFormat:@"%0.f", self.minValue];
290298
self.minValueLabel.font = self.minMaxValueFont;
291-
self.minValueLabel.minimumScaleFactor = 10/self.minValueLabel.font.pointSize;
299+
self.minValueLabel.minimumScaleFactor = 0.5;
292300
self.minValueLabel.textColor = self.minMaxValueTextColor;
293301
self.minValueLabel.hidden = !self.showMinMaxValue;
294302
CGPoint minDotCenter = CGPointMake(dotRadius * cos(self.startAngle) + center.x, dotRadius * sin(self.startAngle) + center.y);
@@ -307,7 +315,7 @@ - (void)drawRect:(CGRect)rect
307315
}
308316
self.maxValueLabel.text = [NSString stringWithFormat:@"%0.f", self.maxValue];
309317
self.maxValueLabel.font = self.minMaxValueFont;
310-
self.maxValueLabel.minimumScaleFactor = 10/self.maxValueLabel.font.pointSize;
318+
self.maxValueLabel.minimumScaleFactor = 0.5;
311319
self.maxValueLabel.textColor = self.minMaxValueTextColor;
312320
self.maxValueLabel.hidden = !self.showMinMaxValue;
313321
CGPoint maxDotCenter = CGPointMake(dotRadius * cos(self.endAngle) + center.x, dotRadius * sin(self.endAngle) + center.y);
@@ -324,7 +332,7 @@ - (void)drawRect:(CGRect)rect
324332
self.unitOfMeasurementLabel.text = self.unitOfMeasurement;
325333
self.unitOfMeasurementLabel.font = self.unitOfMeasurementFont;
326334
self.unitOfMeasurementLabel.adjustsFontSizeToFitWidth = YES;
327-
self.unitOfMeasurementLabel.minimumScaleFactor = 10/self.unitOfMeasurementLabel.font.pointSize;
335+
self.unitOfMeasurementLabel.minimumScaleFactor = 0.5;
328336
self.unitOfMeasurementLabel.textColor = self.unitOfMeasurementTextColor;
329337
[self addSubview:self.unitOfMeasurementLabel];
330338
self.unitOfMeasurementLabel.hidden = !self.showUnitOfMeasurement;
@@ -367,7 +375,12 @@ - (void)setValue:(CGFloat)value
367375
/*!
368376
* Set text for value label
369377
*/
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+
}
371384

372385
/*!
373386
* Trigger the stoke animation of ring layer.
@@ -516,7 +529,6 @@ - (void)setValueFont:(UIFont *)valueFont
516529
_valueFont = valueFont;
517530

518531
self.valueLabel.font = _valueFont;
519-
self.valueLabel.minimumScaleFactor = 10/_valueFont.pointSize;
520532
}
521533
}
522534

@@ -580,7 +592,6 @@ - (void)setUnitOfMeasurementFont:(UIFont *)unitOfMeasurementFont
580592
_unitOfMeasurementFont = unitOfMeasurementFont;
581593

582594
self.unitOfMeasurementLabel.font = _unitOfMeasurementFont;
583-
self.unitOfMeasurementLabel.minimumScaleFactor = 10/_unitOfMeasurementFont.pointSize;
584595
}
585596
}
586597

LMGaugeViewDemo/LMGaugeViewDemo/LMGaugeViewDemo-Info.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.0.4</string>
20+
<string>1.0.5</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
24-
<string>40</string>
24+
<string>50</string>
2525
<key>LSRequiresIPhoneOS</key>
2626
<true/>
2727
<key>UILaunchStoryboardName</key>

0 commit comments

Comments
 (0)