Skip to content

Commit f6d3b9b

Browse files
committed
Show min/max value
1 parent 37932c0 commit f6d3b9b

File tree

7 files changed

+124
-30
lines changed

7 files changed

+124
-30
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.2"
4+
s.version = "1.0.3"
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

+15
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ IB_DESIGNABLE
103103
*/
104104
@property (nonatomic, strong) IBInspectable UIColor *valueTextColor;
105105

106+
/*!
107+
* A boolean indicates whether to show min/max value.
108+
*/
109+
@property (nonatomic, assign) IBInspectable BOOL showMinMaxValue;
110+
111+
/*!
112+
* Font of min/max value label.
113+
*/
114+
@property (nonatomic, strong) IBInspectable UIFont *minMaxValueFont;
115+
116+
/*!
117+
* Text color of min/max value label.
118+
*/
119+
@property (nonatomic, strong) IBInspectable UIColor *minMaxValueTextColor;
120+
106121
/*!
107122
* A boolean indicates whether to show unit of measurement.
108123
*/

LMGaugeView/LMGaugeView.m

+73-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
#define kDefaultLimitDotRadius 2
3131
#define kDefaultLimitDotColor [UIColor redColor]
3232

33-
#define kDefaultValueFont [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:150]
33+
#define kDefaultValueFont [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:140]
3434
#define kDefaultValueTextColor [UIColor colorWithWhite:0.1 alpha:1]
35+
#define kDefaultMinMaxValueFont [UIFont fontWithName:@"HelveticaNeue" size:12]
36+
#define kDefaultMinMaxValueTextColor [UIColor colorWithWhite:0.3 alpha:1]
3537

3638
#define kDefaultUnitOfMeasurement @"km/h"
3739
#define kDefaultUnitOfMeasurementFont [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:16]
@@ -48,6 +50,8 @@ @interface LMGaugeView ()
4850
@property (nonatomic, strong) CAShapeLayer *progressLayer;
4951
@property (nonatomic, strong) UILabel *valueLabel;
5052
@property (nonatomic, strong) UILabel *unitOfMeasurementLabel;
53+
@property (nonatomic, strong) UILabel *minValueLabel;
54+
@property (nonatomic, strong) UILabel *maxValueLabel;
5155

5256
@end
5357

@@ -111,6 +115,9 @@ - (void)initialize
111115
// Value Text
112116
_valueFont = kDefaultValueFont;
113117
_valueTextColor = kDefaultValueTextColor;
118+
_showMinMaxValue = YES;
119+
_minMaxValueFont = kDefaultMinMaxValueFont;
120+
_minMaxValueTextColor = kDefaultMinMaxValueTextColor;
114121

115122
// Unit Of Measurement
116123
_showUnitOfMeasurement = YES;
@@ -261,6 +268,44 @@ - (void)drawRect:(CGRect)rect
261268
self.valueLabel.frame = CGRectInset(self.progressLayer.frame, insetX, insetX);
262269
self.valueLabel.frame = CGRectOffset(self.valueLabel.frame, 0, self.showUnitOfMeasurement ? -self.divisionsPadding/2 : 0);
263270

271+
/*!
272+
* Min Value Label
273+
*/
274+
if (!self.minValueLabel)
275+
{
276+
self.minValueLabel = [[UILabel alloc] init];
277+
self.minValueLabel.backgroundColor = [UIColor clearColor];
278+
self.minValueLabel.textAlignment = NSTextAlignmentLeft;
279+
self.minValueLabel.adjustsFontSizeToFitWidth = YES;
280+
[self addSubview:self.minValueLabel];
281+
}
282+
self.minValueLabel.text = [NSString stringWithFormat:@"%0.f", self.minValue];
283+
self.minValueLabel.font = self.minMaxValueFont;
284+
self.minValueLabel.minimumScaleFactor = 10/self.minValueLabel.font.pointSize;
285+
self.minValueLabel.textColor = self.minMaxValueTextColor;
286+
self.minValueLabel.hidden = !self.showMinMaxValue;
287+
CGPoint minDotCenter = CGPointMake(dotRadius * cos(self.startAngle) + center.x, dotRadius * sin(self.startAngle) + center.y);
288+
self.minValueLabel.frame = CGRectMake(minDotCenter.x + 8, minDotCenter.y - 20, 40, 20);
289+
290+
/*!
291+
* Max Value Label
292+
*/
293+
if (!self.maxValueLabel)
294+
{
295+
self.maxValueLabel = [[UILabel alloc] init];
296+
self.maxValueLabel.backgroundColor = [UIColor clearColor];
297+
self.maxValueLabel.textAlignment = NSTextAlignmentRight;
298+
self.maxValueLabel.adjustsFontSizeToFitWidth = YES;
299+
[self addSubview:self.maxValueLabel];
300+
}
301+
self.maxValueLabel.text = [NSString stringWithFormat:@"%0.f", self.maxValue];
302+
self.maxValueLabel.font = self.minMaxValueFont;
303+
self.maxValueLabel.minimumScaleFactor = 10/self.maxValueLabel.font.pointSize;
304+
self.maxValueLabel.textColor = self.minMaxValueTextColor;
305+
self.maxValueLabel.hidden = !self.showMinMaxValue;
306+
CGPoint maxDotCenter = CGPointMake(dotRadius * cos(self.endAngle) + center.x, dotRadius * sin(self.endAngle) + center.y);
307+
self.maxValueLabel.frame = CGRectMake(maxDotCenter.x - 8 - 40, maxDotCenter.y - 20, 40, 20);
308+
264309
/*!
265310
* Unit Of Measurement Label
266311
*/
@@ -477,6 +522,33 @@ - (void)setValueTextColor:(UIColor *)valueTextColor
477522
}
478523
}
479524

525+
- (void)setShowMinMaxValue:(BOOL)showMinMaxValue
526+
{
527+
if (_showMinMaxValue != showMinMaxValue) {
528+
_showMinMaxValue = showMinMaxValue;
529+
530+
[self setNeedsDisplay];
531+
}
532+
}
533+
534+
- (void)setMinMaxValueFont:(UIFont *)minMaxValueFont
535+
{
536+
if (_minMaxValueFont != minMaxValueFont) {
537+
_minMaxValueFont = minMaxValueFont;
538+
539+
[self setNeedsDisplay];
540+
}
541+
}
542+
543+
- (void)setMinMaxValueTextColor:(UIColor *)minMaxValueTextColor
544+
{
545+
if (_minMaxValueTextColor != minMaxValueTextColor) {
546+
_minMaxValueTextColor = minMaxValueTextColor;
547+
548+
[self setNeedsDisplay];
549+
}
550+
}
551+
480552
- (void)setShowUnitOfMeasurement:(BOOL)showUnitOfMeasurement
481553
{
482554
if (_showUnitOfMeasurement != showUnitOfMeasurement) {

LMGaugeViewDemo/LMGaugeViewDemo.xcodeproj/project.pbxproj

+15-5
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
isa = PBXProject;
146146
attributes = {
147147
CLASSPREFIX = LM;
148-
LastUpgradeCheck = 0710;
148+
LastUpgradeCheck = 0820;
149149
ORGANIZATIONNAME = LMinh;
150150
};
151151
buildConfigurationList = 62166418198AB252009AD267 /* Build configuration list for PBXProject "LMGaugeViewDemo" */;
@@ -227,14 +227,19 @@
227227
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
228228
CLANG_WARN_EMPTY_BODY = YES;
229229
CLANG_WARN_ENUM_CONVERSION = YES;
230+
CLANG_WARN_INFINITE_RECURSION = YES;
230231
CLANG_WARN_INT_CONVERSION = YES;
231232
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
233+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
234+
CLANG_WARN_UNREACHABLE_CODE = YES;
232235
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
233236
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
234237
COPY_PHASE_STRIP = NO;
238+
ENABLE_STRICT_OBJC_MSGSEND = YES;
235239
ENABLE_TESTABILITY = YES;
236240
GCC_C_LANGUAGE_STANDARD = gnu99;
237241
GCC_DYNAMIC_NO_PIC = NO;
242+
GCC_NO_COMMON_BLOCKS = YES;
238243
GCC_OPTIMIZATION_LEVEL = 0;
239244
GCC_PREPROCESSOR_DEFINITIONS = (
240245
"DEBUG=1",
@@ -247,7 +252,7 @@
247252
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
248253
GCC_WARN_UNUSED_FUNCTION = YES;
249254
GCC_WARN_UNUSED_VARIABLE = YES;
250-
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
255+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
251256
ONLY_ACTIVE_ARCH = YES;
252257
SDKROOT = iphoneos;
253258
};
@@ -266,20 +271,25 @@
266271
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
267272
CLANG_WARN_EMPTY_BODY = YES;
268273
CLANG_WARN_ENUM_CONVERSION = YES;
274+
CLANG_WARN_INFINITE_RECURSION = YES;
269275
CLANG_WARN_INT_CONVERSION = YES;
270276
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
277+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
278+
CLANG_WARN_UNREACHABLE_CODE = YES;
271279
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
272280
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
273281
COPY_PHASE_STRIP = YES;
274282
ENABLE_NS_ASSERTIONS = NO;
283+
ENABLE_STRICT_OBJC_MSGSEND = YES;
275284
GCC_C_LANGUAGE_STANDARD = gnu99;
285+
GCC_NO_COMMON_BLOCKS = YES;
276286
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
277287
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
278288
GCC_WARN_UNDECLARED_SELECTOR = YES;
279289
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
280290
GCC_WARN_UNUSED_FUNCTION = YES;
281291
GCC_WARN_UNUSED_VARIABLE = YES;
282-
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
292+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
283293
SDKROOT = iphoneos;
284294
VALIDATE_PRODUCT = YES;
285295
};
@@ -293,7 +303,7 @@
293303
GCC_PRECOMPILE_PREFIX_HEADER = YES;
294304
GCC_PREFIX_HEADER = "LMGaugeViewDemo/LMGaugeViewDemo-Prefix.pch";
295305
INFOPLIST_FILE = "LMGaugeViewDemo/LMGaugeViewDemo-Info.plist";
296-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
306+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
297307
PRODUCT_BUNDLE_IDENTIFIER = "com.lminh.${PRODUCT_NAME:rfc1034identifier}";
298308
PRODUCT_NAME = LMGaugeView;
299309
WRAPPER_EXTENSION = app;
@@ -308,7 +318,7 @@
308318
GCC_PRECOMPILE_PREFIX_HEADER = YES;
309319
GCC_PREFIX_HEADER = "LMGaugeViewDemo/LMGaugeViewDemo-Prefix.pch";
310320
INFOPLIST_FILE = "LMGaugeViewDemo/LMGaugeViewDemo-Info.plist";
311-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
321+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
312322
PRODUCT_BUNDLE_IDENTIFIER = "com.lminh.${PRODUCT_NAME:rfc1034identifier}";
313323
PRODUCT_NAME = LMGaugeView;
314324
WRAPPER_EXTENSION = app;

LMGaugeViewDemo/LMGaugeViewDemo.xcodeproj/xcuserdata/lminh.xcuserdatad/xcschemes/LMGaugeViewDemo.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0710"
3+
LastUpgradeVersion = "0820"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
47
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
69
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
10+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
711
</dependencies>
812
<scenes>
913
<!--Delegate-->
@@ -15,48 +19,36 @@
1519
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
1620
</layoutGuides>
1721
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
18-
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
22+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1923
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2024
<subviews>
2125
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="UgZ-WN-tPe" customClass="LMGaugeView">
22-
<rect key="frame" x="20" y="114" width="280" height="280"/>
23-
<animations/>
24-
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
26+
<rect key="frame" x="20" y="136" width="335" height="335"/>
27+
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
2528
<constraints>
2629
<constraint firstAttribute="width" secondItem="UgZ-WN-tPe" secondAttribute="height" multiplier="1:1" id="x0s-rf-4tG"/>
2730
</constraints>
28-
<userDefinedRuntimeAttributes>
29-
<userDefinedRuntimeAttribute type="number" keyPath="limitValue">
30-
<real key="value" value="33"/>
31-
</userDefinedRuntimeAttribute>
32-
<userDefinedRuntimeAttribute type="number" keyPath="maxValue">
33-
<real key="value" value="81"/>
34-
</userDefinedRuntimeAttribute>
35-
</userDefinedRuntimeAttributes>
3631
<connections>
3732
<outlet property="delegate" destination="vXZ-lx-hvc" id="Fmj-n4-TBj"/>
3833
</connections>
3934
</view>
4035
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="IR3-O8-TRX">
41-
<rect key="frame" x="134" y="487" width="51" height="31"/>
42-
<animations/>
36+
<rect key="frame" x="161.5" y="586" width="51" height="31"/>
4337
<connections>
4438
<action selector="changedStyleSwitchValueChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="Kq5-AS-1ZL"/>
4539
</connections>
4640
</switch>
4741
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Developed by LMinh" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DcH-fn-VJ8" userLabel="Label - About">
48-
<rect key="frame" x="20" y="538" width="280" height="20"/>
49-
<animations/>
42+
<rect key="frame" x="20" y="637" width="335" height="20"/>
5043
<constraints>
5144
<constraint firstAttribute="height" constant="20" id="jQR-oE-QbD"/>
5245
</constraints>
5346
<fontDescription key="fontDescription" name="HelveticaNeue-Thin" family="Helvetica Neue" pointSize="16"/>
54-
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
47+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
5548
<nil key="highlightedColor"/>
5649
</label>
5750
</subviews>
58-
<animations/>
59-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
51+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
6052
<constraints>
6153
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="DcH-fn-VJ8" secondAttribute="bottom" constant="10" id="8Oe-gH-qFC"/>
6254
<constraint firstAttribute="centerY" secondItem="UgZ-WN-tPe" secondAttribute="centerY" constant="30" id="8Xq-JF-rxf"/>
@@ -80,4 +72,9 @@
8072
<point key="canvasLocation" x="-12" y="358"/>
8173
</scene>
8274
</scenes>
75+
<simulatedMetricsContainer key="defaultSimulatedMetrics">
76+
<simulatedStatusBarMetrics key="statusBar"/>
77+
<simulatedOrientationMetrics key="orientation"/>
78+
<simulatedScreenMetrics key="destination" type="retina4_7.fullscreen"/>
79+
</simulatedMetricsContainer>
8380
</document>

0 commit comments

Comments
 (0)