Skip to content

Commit

Permalink
Error: invalid numeric value to CoreGraphics API #1
Browse files Browse the repository at this point in the history
  • Loading branch information
lminhtm committed Nov 16, 2015
1 parent 2e69aa8 commit 6697454
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 23 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.0"
s.version = "1.0.1"
s.summary = "LMGaugeView is a simple and customizable gauge control for iOS."
s.homepage = "https://github.com/lminhtm/LMGaugeView"
s.license = 'MIT'
Expand Down
14 changes: 7 additions & 7 deletions LMGaugeView/LMGaugeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ - (void)strokeGauge
/*!
* Set progress for ring layer
*/
CGFloat progress = (self.value - self.minValue)/self.maxValue;
CGFloat progress = self.maxValue ? (self.value - self.minValue)/self.maxValue : 0;
self.progressLayer.strokeEnd = progress;

/*!
Expand All @@ -148,8 +148,8 @@ - (void)drawRect:(CGRect)rect
/*!
* Prepare drawing
*/
self.divisionUnitValue = (self.maxValue - self.minValue)/self.numOfDivisions;
self.divisionUnitAngle = (M_PI * 2 - ABS(self.endAngle - self.startAngle))/self.numOfDivisions;
self.divisionUnitValue = self.numOfDivisions ? (self.maxValue - self.minValue)/self.numOfDivisions : 0;
self.divisionUnitAngle = self.numOfDivisions ? (M_PI * 2 - ABS(self.endAngle - self.startAngle))/self.numOfDivisions : 0;
CGPoint center = CGPointMake(CGRectGetWidth(self.bounds)/2, CGRectGetHeight(self.bounds)/2);
CGFloat ringRadius = MIN(CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds))/2 - self.ringThickness/2;
CGFloat dotRadius = ringRadius - self.ringThickness/2 - self.divisionsPadding - self.divisionsRadius/2;
Expand All @@ -176,11 +176,11 @@ - (void)drawRect:(CGRect)rect
/*!
* Draw divisions and subdivisions
*/
for (int i = 0; i <= self.numOfDivisions; i++)
for (int i = 0; i <= self.numOfDivisions && self.numOfDivisions != 0; i++)
{
if (i != self.numOfDivisions)
{
for (int j = 0; j <= self.numOfSubDivisions; j++)
for (int j = 0; j <= self.numOfSubDivisions && self.numOfSubDivisions != 0; j++)
{
// Subdivisions
CGFloat value = i * self.divisionUnitValue + j * self.divisionUnitValue/self.numOfSubDivisions;
Expand All @@ -206,7 +206,7 @@ - (void)drawRect:(CGRect)rect
/*!
* Draw the limit dot
*/
if (self.showLimitDot)
if (self.showLimitDot && self.numOfDivisions != 0)
{
CGFloat angle = [self angleFromValue:self.limitValue];
CGPoint dotCenter = CGPointMake(dotRadius * cos(angle) + center.x, dotRadius * sin(angle) + center.y);
Expand Down Expand Up @@ -288,7 +288,7 @@ - (void)drawRect:(CGRect)rect

- (CGFloat)angleFromValue:(CGFloat)value
{
CGFloat level = ((value - self.minValue)/self.divisionUnitValue);
CGFloat level = self.divisionUnitValue ? (value - self.minValue)/self.divisionUnitValue : 0;
CGFloat angle = level * self.divisionUnitAngle + self.startAngle;
return angle;
}
Expand Down
9 changes: 8 additions & 1 deletion LMGaugeViewDemo/LMGaugeViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
5C8E55721BF977A0009C38FC /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5C8E55711BF977A0009C38FC /* Launch Screen.storyboard */; };
5CE9FFE71B6C7058004C633B /* LMGaugeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5CE9FFE61B6C7058004C633B /* LMGaugeView.m */; };
62166421198AB252009AD267 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 62166420198AB252009AD267 /* Foundation.framework */; };
62166423198AB252009AD267 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 62166422198AB252009AD267 /* CoreGraphics.framework */; };
Expand All @@ -20,6 +21,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
5C8E55711BF977A0009C38FC /* Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
5CE9FFE51B6C7058004C633B /* LMGaugeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LMGaugeView.h; sourceTree = "<group>"; };
5CE9FFE61B6C7058004C633B /* LMGaugeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LMGaugeView.m; sourceTree = "<group>"; };
6216641D198AB252009AD267 /* LMGaugeView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LMGaugeView.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -107,6 +109,7 @@
isa = PBXGroup;
children = (
62166438198AB252009AD267 /* Images.xcassets */,
5C8E55711BF977A0009C38FC /* Launch Screen.storyboard */,
62166428198AB252009AD267 /* LMGaugeViewDemo-Info.plist */,
62166429198AB252009AD267 /* InfoPlist.strings */,
6216642C198AB252009AD267 /* main.m */,
Expand Down Expand Up @@ -142,7 +145,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = LM;
LastUpgradeCheck = 0510;
LastUpgradeCheck = 0710;
ORGANIZATIONNAME = LMinh;
};
buildConfigurationList = 62166418198AB252009AD267 /* Build configuration list for PBXProject "LMGaugeViewDemo" */;
Expand Down Expand Up @@ -170,6 +173,7 @@
files = (
62166439198AB252009AD267 /* Images.xcassets in Resources */,
6216642B198AB252009AD267 /* InfoPlist.strings in Resources */,
5C8E55721BF977A0009C38FC /* Launch Screen.storyboard in Resources */,
62166434198AB252009AD267 /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -228,6 +232,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -289,6 +294,7 @@
GCC_PREFIX_HEADER = "LMGaugeViewDemo/LMGaugeViewDemo-Prefix.pch";
INFOPLIST_FILE = "LMGaugeViewDemo/LMGaugeViewDemo-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.lminh.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = LMGaugeView;
WRAPPER_EXTENSION = app;
};
Expand All @@ -303,6 +309,7 @@
GCC_PREFIX_HEADER = "LMGaugeViewDemo/LMGaugeViewDemo-Prefix.pch";
INFOPLIST_FILE = "LMGaugeViewDemo/LMGaugeViewDemo-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.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 = "0640"
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -23,10 +23,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
Expand All @@ -38,15 +38,18 @@
ReferencedContainer = "container:LMGaugeViewDemo.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand All @@ -62,10 +65,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
15 changes: 7 additions & 8 deletions LMGaugeViewDemo/LMGaugeViewDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<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">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
</dependencies>
<scenes>
<!--View Controller-->
<!--Delegate-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController id="vXZ-lx-hvc" customClass="LMViewController" sceneMemberID="viewController">
Expand All @@ -20,6 +20,7 @@
<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"/>
<constraints>
<constraint firstAttribute="width" secondItem="UgZ-WN-tPe" secondAttribute="height" multiplier="1:1" id="x0s-rf-4tG"/>
Expand All @@ -38,12 +39,14 @@
</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/>
<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/>
<constraints>
<constraint firstAttribute="height" constant="20" id="jQR-oE-QbD"/>
</constraints>
Expand All @@ -52,6 +55,7 @@
<nil key="highlightedColor"/>
</label>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="DcH-fn-VJ8" secondAttribute="bottom" constant="10" id="8Oe-gH-qFC"/>
Expand All @@ -76,9 +80,4 @@
<point key="canvasLocation" x="-12" y="358"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
4 changes: 3 additions & 1 deletion LMGaugeViewDemo/LMGaugeViewDemo/LMGaugeViewDemo-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.lminh.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand All @@ -24,6 +24,8 @@
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>Launch Screen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down
53 changes: 53 additions & 0 deletions LMGaugeViewDemo/LMGaugeViewDemo/Launch Screen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright © 2015 LMinh. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
<rect key="frame" x="20" y="559" width="560" height="21"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="LMGaugeViewDemo" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
<rect key="frame" x="20" y="180" width="560" height="43"/>
<animations/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="centerX" secondItem="obG-Y5-kRd" secondAttribute="centerX" id="5cz-MP-9tL"/>
<constraint firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
<constraint firstItem="obG-Y5-kRd" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" constant="20" symbolic="YES" id="SfN-ll-jLj"/>
<constraint firstAttribute="bottom" secondItem="obG-Y5-kRd" secondAttribute="bottom" constant="20" id="Y44-ml-fuU"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="bottom" multiplier="1/3" constant="1" id="moa-c2-u7t"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" constant="20" symbolic="YES" id="x7j-FC-K8j"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="371" y="372"/>
</scene>
</scenes>
</document>

0 comments on commit 6697454

Please sign in to comment.