Skip to content

Commit

Permalink
Show min/max value
Browse files Browse the repository at this point in the history
  • Loading branch information
lminhtm committed Mar 12, 2017
1 parent 37932c0 commit f6d3b9b
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 30 deletions.
2 changes: 1 addition & 1 deletion LMGaugeView.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "LMGaugeView"
s.version = "1.0.2"
s.version = "1.0.3"
s.summary = "LMGaugeView is a simple and customizable gauge control for iOS."
s.homepage = "https://github.com/lminhtm/LMGaugeView"
s.license = 'MIT'
Expand Down
15 changes: 15 additions & 0 deletions LMGaugeView/LMGaugeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ IB_DESIGNABLE
*/
@property (nonatomic, strong) IBInspectable UIColor *valueTextColor;

/*!
* A boolean indicates whether to show min/max value.
*/
@property (nonatomic, assign) IBInspectable BOOL showMinMaxValue;

/*!
* Font of min/max value label.
*/
@property (nonatomic, strong) IBInspectable UIFont *minMaxValueFont;

/*!
* Text color of min/max value label.
*/
@property (nonatomic, strong) IBInspectable UIColor *minMaxValueTextColor;

/*!
* A boolean indicates whether to show unit of measurement.
*/
Expand Down
74 changes: 73 additions & 1 deletion LMGaugeView/LMGaugeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
#define kDefaultLimitDotRadius 2
#define kDefaultLimitDotColor [UIColor redColor]

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

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

@end

Expand Down Expand Up @@ -111,6 +115,9 @@ - (void)initialize
// Value Text
_valueFont = kDefaultValueFont;
_valueTextColor = kDefaultValueTextColor;
_showMinMaxValue = YES;
_minMaxValueFont = kDefaultMinMaxValueFont;
_minMaxValueTextColor = kDefaultMinMaxValueTextColor;

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

/*!
* Min Value Label
*/
if (!self.minValueLabel)
{
self.minValueLabel = [[UILabel alloc] init];
self.minValueLabel.backgroundColor = [UIColor clearColor];
self.minValueLabel.textAlignment = NSTextAlignmentLeft;
self.minValueLabel.adjustsFontSizeToFitWidth = YES;
[self addSubview:self.minValueLabel];
}
self.minValueLabel.text = [NSString stringWithFormat:@"%0.f", self.minValue];
self.minValueLabel.font = self.minMaxValueFont;
self.minValueLabel.minimumScaleFactor = 10/self.minValueLabel.font.pointSize;
self.minValueLabel.textColor = self.minMaxValueTextColor;
self.minValueLabel.hidden = !self.showMinMaxValue;
CGPoint minDotCenter = CGPointMake(dotRadius * cos(self.startAngle) + center.x, dotRadius * sin(self.startAngle) + center.y);
self.minValueLabel.frame = CGRectMake(minDotCenter.x + 8, minDotCenter.y - 20, 40, 20);

/*!
* Max Value Label
*/
if (!self.maxValueLabel)
{
self.maxValueLabel = [[UILabel alloc] init];
self.maxValueLabel.backgroundColor = [UIColor clearColor];
self.maxValueLabel.textAlignment = NSTextAlignmentRight;
self.maxValueLabel.adjustsFontSizeToFitWidth = YES;
[self addSubview:self.maxValueLabel];
}
self.maxValueLabel.text = [NSString stringWithFormat:@"%0.f", self.maxValue];
self.maxValueLabel.font = self.minMaxValueFont;
self.maxValueLabel.minimumScaleFactor = 10/self.maxValueLabel.font.pointSize;
self.maxValueLabel.textColor = self.minMaxValueTextColor;
self.maxValueLabel.hidden = !self.showMinMaxValue;
CGPoint maxDotCenter = CGPointMake(dotRadius * cos(self.endAngle) + center.x, dotRadius * sin(self.endAngle) + center.y);
self.maxValueLabel.frame = CGRectMake(maxDotCenter.x - 8 - 40, maxDotCenter.y - 20, 40, 20);

/*!
* Unit Of Measurement Label
*/
Expand Down Expand Up @@ -477,6 +522,33 @@ - (void)setValueTextColor:(UIColor *)valueTextColor
}
}

- (void)setShowMinMaxValue:(BOOL)showMinMaxValue
{
if (_showMinMaxValue != showMinMaxValue) {
_showMinMaxValue = showMinMaxValue;

[self setNeedsDisplay];
}
}

- (void)setMinMaxValueFont:(UIFont *)minMaxValueFont
{
if (_minMaxValueFont != minMaxValueFont) {
_minMaxValueFont = minMaxValueFont;

[self setNeedsDisplay];
}
}

- (void)setMinMaxValueTextColor:(UIColor *)minMaxValueTextColor
{
if (_minMaxValueTextColor != minMaxValueTextColor) {
_minMaxValueTextColor = minMaxValueTextColor;

[self setNeedsDisplay];
}
}

- (void)setShowUnitOfMeasurement:(BOOL)showUnitOfMeasurement
{
if (_showUnitOfMeasurement != showUnitOfMeasurement) {
Expand Down
20 changes: 15 additions & 5 deletions LMGaugeViewDemo/LMGaugeViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = LM;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = LMinh;
};
buildConfigurationList = 62166418198AB252009AD267 /* Build configuration list for PBXProject "LMGaugeViewDemo" */;
Expand Down Expand Up @@ -227,14 +227,19 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand All @@ -247,7 +252,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
Expand All @@ -266,20 +271,25 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
Expand All @@ -293,7 +303,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "LMGaugeViewDemo/LMGaugeViewDemo-Prefix.pch";
INFOPLIST_FILE = "LMGaugeViewDemo/LMGaugeViewDemo-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.lminh.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = LMGaugeView;
WRAPPER_EXTENSION = app;
Expand All @@ -308,7 +318,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "LMGaugeViewDemo/LMGaugeViewDemo-Prefix.pch";
INFOPLIST_FILE = "LMGaugeViewDemo/LMGaugeViewDemo-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.lminh.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = LMGaugeView;
WRAPPER_EXTENSION = app;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
41 changes: 19 additions & 22 deletions LMGaugeViewDemo/LMGaugeViewDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<?xml version="1.0" encoding="UTF-8"?>
<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">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Delegate-->
Expand All @@ -15,48 +19,36 @@
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="UgZ-WN-tPe" customClass="LMGaugeView">
<rect key="frame" x="20" y="114" width="280" height="280"/>
<animations/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<rect key="frame" x="20" y="136" width="335" height="335"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" secondItem="UgZ-WN-tPe" secondAttribute="height" multiplier="1:1" id="x0s-rf-4tG"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="limitValue">
<real key="value" value="33"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="maxValue">
<real key="value" value="81"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<outlet property="delegate" destination="vXZ-lx-hvc" id="Fmj-n4-TBj"/>
</connections>
</view>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="IR3-O8-TRX">
<rect key="frame" x="134" y="487" width="51" height="31"/>
<animations/>
<rect key="frame" x="161.5" y="586" width="51" height="31"/>
<connections>
<action selector="changedStyleSwitchValueChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="Kq5-AS-1ZL"/>
</connections>
</switch>
<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">
<rect key="frame" x="20" y="538" width="280" height="20"/>
<animations/>
<rect key="frame" x="20" y="637" width="335" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="jQR-oE-QbD"/>
</constraints>
<fontDescription key="fontDescription" name="HelveticaNeue-Thin" family="Helvetica Neue" pointSize="16"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="DcH-fn-VJ8" secondAttribute="bottom" constant="10" id="8Oe-gH-qFC"/>
<constraint firstAttribute="centerY" secondItem="UgZ-WN-tPe" secondAttribute="centerY" constant="30" id="8Xq-JF-rxf"/>
Expand All @@ -80,4 +72,9 @@
<point key="canvasLocation" x="-12" y="358"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4_7.fullscreen"/>
</simulatedMetricsContainer>
</document>

0 comments on commit f6d3b9b

Please sign in to comment.