Toggle navigation
Toggle navigation
This project
Loading...
Sign in
iOS
/
PNChart
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
kevin
2013-12-01 01:02:53 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
41d1ff37e669f850fb18d9413304a635447a2e8f
41d1ff37
1 parent
a1518081
Add Circle Chart demo
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
173 additions
and
19 deletions
PNChartDemo.xcodeproj/project.pbxproj
PNChartDemo/PCChartViewController.m
PNChartDemo/PNChart/PNChart.h
PNChartDemo/PNChart/PNChart.m
PNChartDemo/PNChart/PNCircleChart.h
PNChartDemo/PNChart/PNCircleChart.m
PNChartDemo.xcodeproj/project.pbxproj
View file @
41d1ff3
...
...
@@ -29,6 +29,7 @@
0AF7A8BE182AEB99003645C4 /* PNChartLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AF7A8BB182AEB99003645C4 /* PNChartLabel.m */; };
0AF7A8BF182AEB99003645C4 /* PNColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AF7A8BD182AEB99003645C4 /* PNColor.m */; };
9F55483E18498E0E004073B5 /* PNCircleChart.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F55483D18498E0E004073B5 /* PNCircleChart.m */; };
9F656B51184A4E34002E5675 /* UICountingLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F656B50184A4E34002E5675 /* UICountingLabel.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
...
...
@@ -76,6 +77,8 @@
0AF7A8BD182AEB99003645C4 /* PNColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PNColor.m; path = PNChart/PNColor.m; sourceTree = "<group>"; };
9F55483C18498E0E004073B5 /* PNCircleChart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PNCircleChart.h; path = PNChart/PNCircleChart.h; sourceTree = "<group>"; };
9F55483D18498E0E004073B5 /* PNCircleChart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PNCircleChart.m; path = PNChart/PNCircleChart.m; sourceTree = "<group>"; };
9F656B4F184A4E34002E5675 /* UICountingLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UICountingLabel.h; path = PNChart/ThirdPart/UICountingLabel.h; sourceTree = "<group>"; };
9F656B50184A4E34002E5675 /* UICountingLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UICountingLabel.m; path = PNChart/ThirdPart/UICountingLabel.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
...
...
@@ -180,20 +183,12 @@
0AF7A8A2182AAAB3003645C4 /* PNChart */ = {
isa = PBXGroup;
children = (
0AF7A8BA182AEB99003645C4 /* PNChartLabel.h */,
0AF7A8BB182AEB99003645C4 /* PNChartLabel.m */,
0AF7A8BC182AEB99003645C4 /* PNColor.h */,
0AF7A8BD182AEB99003645C4 /* PNColor.m */,
9F656B49184A4B90002E5675 /* PNLineChart */,
9F656B4A184A4BAC002E5675 /* PNChartUI */,
0AF7A89F182AAAAA003645C4 /* PNChart.h */,
0AF7A8A0182AAAAA003645C4 /* PNChart.m */,
0AF7A8B1182AC604003645C4 /* PNLineChart.h */,
0AF7A8B2182AC604003645C4 /* PNLineChart.m */,
0AF7A8B4182ADDEB003645C4 /* PNBarChart.h */,
0AF7A8B5182ADDEB003645C4 /* PNBarChart.m */,
0AF7A8B7182AEB80003645C4 /* PNBar.h */,
0AF7A8B8182AEB80003645C4 /* PNBar.m */,
9F55483C18498E0E004073B5 /* PNCircleChart.h */,
9F55483D18498E0E004073B5 /* PNCircleChart.m */,
9F656B48184A4B83002E5675 /* PNBarChart */,
9F656B4B184A4BC9002E5675 /* PNCircleChart */,
);
name = PNChart;
sourceTree = "<group>";
...
...
@@ -207,6 +202,48 @@
name = PCChartViewController;
sourceTree = "<group>";
};
9F656B48184A4B83002E5675 /* PNBarChart */ = {
isa = PBXGroup;
children = (
0AF7A8B4182ADDEB003645C4 /* PNBarChart.h */,
0AF7A8B5182ADDEB003645C4 /* PNBarChart.m */,
0AF7A8B7182AEB80003645C4 /* PNBar.h */,
0AF7A8B8182AEB80003645C4 /* PNBar.m */,
);
name = PNBarChart;
sourceTree = "<group>";
};
9F656B49184A4B90002E5675 /* PNLineChart */ = {
isa = PBXGroup;
children = (
0AF7A8B1182AC604003645C4 /* PNLineChart.h */,
0AF7A8B2182AC604003645C4 /* PNLineChart.m */,
);
name = PNLineChart;
sourceTree = "<group>";
};
9F656B4A184A4BAC002E5675 /* PNChartUI */ = {
isa = PBXGroup;
children = (
0AF7A8BA182AEB99003645C4 /* PNChartLabel.h */,
0AF7A8BB182AEB99003645C4 /* PNChartLabel.m */,
0AF7A8BC182AEB99003645C4 /* PNColor.h */,
0AF7A8BD182AEB99003645C4 /* PNColor.m */,
);
name = PNChartUI;
sourceTree = "<group>";
};
9F656B4B184A4BC9002E5675 /* PNCircleChart */ = {
isa = PBXGroup;
children = (
9F656B4F184A4E34002E5675 /* UICountingLabel.h */,
9F656B50184A4E34002E5675 /* UICountingLabel.m */,
9F55483C18498E0E004073B5 /* PNCircleChart.h */,
9F55483D18498E0E004073B5 /* PNCircleChart.m */,
);
name = PNCircleChart;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
...
...
@@ -306,6 +343,7 @@
buildActionMask = 2147483647;
files = (
0AF7A8AF182AAEEF003645C4 /* PCChartViewController.m in Sources */,
9F656B51184A4E34002E5675 /* UICountingLabel.m in Sources */,
0AF7A8BF182AEB99003645C4 /* PNColor.m in Sources */,
0AF7A8BE182AEB99003645C4 /* PNChartLabel.m in Sources */,
0AF7A8B9182AEB80003645C4 /* PNBar.m in Sources */,
...
...
PNChartDemo/PCChartViewController.m
View file @
41d1ff3
...
...
@@ -50,6 +50,26 @@
[
barChart
strokeChart
];
[
self
.
chartScrollView
addSubview
:
barChartLabel
];
[
self
.
chartScrollView
addSubview
:
barChart
];
//Add CircleChart
UILabel
*
circleChartLabel
=
[[
UILabel
alloc
]
initWithFrame
:
CGRectMake
(
0
,
550
,
SCREEN_WIDTH
,
30
)];
circleChartLabel
.
text
=
@"Circle Chart"
;
circleChartLabel
.
textColor
=
PNFreshGreen
;
circleChartLabel
.
font
=
[
UIFont
fontWithName
:
@"Avenir-Medium"
size
:
23
.
0
];
circleChartLabel
.
textAlignment
=
NSTextAlignmentCenter
;
PNChart
*
circleChart
=
[[
PNChart
alloc
]
initWithFrame
:
CGRectMake
(
0
,
585
.
0
,
SCREEN_WIDTH
,
200
.
0
)];
circleChart
.
backgroundColor
=
[
UIColor
clearColor
];
circleChart
.
type
=
PNCircleType
;
circleChart
.
total
=
[
NSNumber
numberWithInt
:
100
];
circleChart
.
current
=
[
NSNumber
numberWithInt
:
60
];
[
circleChart
strokeChart
];
[
self
.
chartScrollView
addSubview
:
circleChartLabel
];
[
self
.
chartScrollView
addSubview
:
circleChart
];
[
self
.
chartScrollView
setContentSize
:
CGSizeMake
(
SCREEN_WIDTH
,
900
.
0
)];
// Do any additional setup after loading the view.
}
...
...
PNChartDemo/PNChart/PNChart.h
View file @
41d1ff3
...
...
@@ -12,12 +12,15 @@
#import "PNColor.h"
#import "PNLineChart.h"
#import "PNBarChart.h"
#import "PNCircleChart.h"
typedef
enum
{
/** Solid line chart style */
PNLineType
,
/** Bar chart style with bar background color */
PNBarType
PNBarType
,
/** Circle chart */
PNCircleType
}
PNChartType
;
...
...
@@ -48,6 +51,8 @@ typedef enum {
@property
(
strong
,
nonatomic
)
PNBarChart
*
barChart
;
@property
(
strong
,
nonatomic
)
PNCircleChart
*
circleChart
;
/**
* PNChart chart type. The default is PNLineChart.
*
...
...
@@ -63,5 +68,18 @@ typedef enum {
@property
(
nonatomic
,
strong
)
UIColor
*
strokeColor
;
/**
* PNChart circle chart total number.
*
*/
@property
(
nonatomic
,
strong
)
NSNumber
*
total
;
/**
* PNChart circle chart current number.
*
*/
@property
(
nonatomic
,
strong
)
NSNumber
*
current
;
@end
...
...
PNChartDemo/PNChart/PNChart.m
View file @
41d1ff3
...
...
@@ -18,6 +18,7 @@
self
.
backgroundColor
=
[
UIColor
whiteColor
];
self
.
clipsToBounds
=
NO
;
self
.
type
=
PNLineType
;
self
.
strokeColor
=
PNFreshGreen
;
}
return
self
;
...
...
@@ -43,7 +44,15 @@
[
_barChart
setStrokeColor
:
_strokeColor
];
[
_barChart
strokeChart
];
}
}
else
if
(
self
.
type
==
PNCircleType
)
{
_circleChart
=
[[
PNCircleChart
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
self
.
frame
.
size
.
width
,
self
.
frame
.
size
.
height
)
andTotal
:
self
.
total
andCurrent
:
self
.
current
];
_circleChart
.
backgroundColor
=
[
UIColor
clearColor
];
_circleChart
.
lineWidth
=
[
NSNumber
numberWithFloat
:
8
.
0
];
[
_circleChart
setStrokeColor
:
_strokeColor
];
[
_circleChart
strokeChart
];
[
self
addSubview
:
_circleChart
];
}
}
...
...
PNChartDemo/PNChart/PNCircleChart.h
View file @
41d1ff3
...
...
@@ -7,6 +7,10 @@
//
#import <UIKit/UIKit.h>
#import "PNColor.h"
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
@interface
PNCircleChart
:
UIView
...
...
@@ -14,10 +18,11 @@
-
(
id
)
initWithFrame
:(
CGRect
)
frame
andTotal
:(
NSNumber
*
)
total
andCurrent
:(
NSNumber
*
)
current
;
@property
(
nonatomic
,
strong
)
UIColor
*
strokeColor
;
@property
(
nonatomic
,
strong
)
NSNumber
*
total
;
@property
(
nonatomic
,
strong
)
NSNumber
*
current
;
@property
(
nonatomic
,
strong
)
NSNumber
*
lineWidth
;
@property
(
nonatomic
,
strong
)
CAShapeLayer
*
circle
;
@property
(
nonatomic
,
strong
)
CAShapeLayer
*
circleBG
;
@end
...
...
PNChartDemo/PNChart/PNCircleChart.m
View file @
41d1ff3
...
...
@@ -7,19 +7,83 @@
//
#import "PNCircleChart.h"
#import "UICountingLabel.h"
@implementation
PNCircleChart
-
(
id
)
initWithFrame
:(
CGRect
)
frame
-
(
id
)
initWithFrame
:(
CGRect
)
frame
andTotal
:(
NSNumber
*
)
total
andCurrent
:(
NSNumber
*
)
current
{
self
=
[
super
initWithFrame
:
frame
];
if
(
self
)
{
// Initialization code
_total
=
total
;
_current
=
current
;
NSLog
(
@"Total is %f frame is %f"
,[
total
floatValue
],
frame
.
size
.
height
);
UIBezierPath
*
circlePath
=
[
UIBezierPath
bezierPathWithArcCenter
:
CGPointMake
(
self
.
center
.
x
,
self
.
center
.
y
-
25
.
0
)
radius
:
50
.
0
startAngle
:
DEGREES_TO_RADIANS
(
270
)
endAngle
:
DEGREES_TO_RADIANS
(
270
.
01
)
clockwise
:
NO
];
_circle
=
[
CAShapeLayer
layer
];
_circle
.
path
=
circlePath
.
CGPath
;
_circle
.
lineCap
=
kCALineCapRound
;
_circle
.
fillColor
=
[
UIColor
clearColor
].
CGColor
;
_circle
.
lineWidth
=
[
_lineWidth
floatValue
];
_circle
.
zPosition
=
1
;
_circleBG
=
[
CAShapeLayer
layer
];
_circleBG
.
path
=
circlePath
.
CGPath
;
_circleBG
.
lineCap
=
kCALineCapRound
;
_circleBG
.
fillColor
=
[
UIColor
clearColor
].
CGColor
;
_circleBG
.
lineWidth
=
[
_lineWidth
floatValue
];
_circleBG
.
strokeColor
=
PNLightYellow
.
CGColor
;
_circleBG
.
strokeEnd
=
1
.
0
;
_circleBG
.
zPosition
=
-
1
;
[
self
.
layer
addSublayer
:
_circle
];
[
self
.
layer
addSublayer
:
_circleBG
];
}
return
self
;
}
-
(
void
)
strokeChart
{
//Add count label
UICountingLabel
*
gradeLabel
=
[[
UICountingLabel
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
50
.
0
,
50
.
0
)];
[
gradeLabel
setTextAlignment
:
NSTextAlignmentCenter
];
[
gradeLabel
setFont
:[
UIFont
boldSystemFontOfSize
:
13
.
0
f
]];
[
gradeLabel
setTextColor
:
PNDeepGrey
];
[
gradeLabel
setCenter
:
CGPointMake
(
self
.
center
.
x
,
self
.
center
.
y
-
25
.
0
)];
gradeLabel
.
method
=
UILabelCountingMethodEaseInOut
;
gradeLabel
.
format
=
@"%d%%"
;
[
self
addSubview
:
gradeLabel
];
//Add circle params
_circle
.
lineWidth
=
[
_lineWidth
floatValue
];
_circleBG
.
lineWidth
=
[
_lineWidth
floatValue
];
_circleBG
.
strokeEnd
=
1
.
0
;
_circle
.
strokeColor
=
_strokeColor
.
CGColor
;
//Add Animation
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
1
.
0
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
pathAnimation
.
fromValue
=
[
NSNumber
numberWithFloat
:
0
.
0
f
];
pathAnimation
.
toValue
=
[
NSNumber
numberWithFloat
:[
_current
floatValue
]
/
[
_total
floatValue
]];
pathAnimation
.
autoreverses
=
NO
;
[
_circle
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
_circle
.
strokeEnd
=
[
_current
floatValue
]
/
[
_total
floatValue
];
[
gradeLabel
countFrom
:
0
to
:[
_current
floatValue
]
/
[
_total
floatValue
]
*
100
withDuration
:
1
.
0
];
}
/*
// Only override drawRect: if you perform custom drawing.
...
...
Please
register
or
login
to post a comment