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
Kyle Clegg
2014-05-10 19:50:21 -0600
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
61f5cd48c1f1768b15e1bd7fba9b26c61f44965a
61f5cd48
1 parent
ba761828
Made counting label publicly accessible. Adding ability to grow circle.
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
32 deletions
PNChart/PNCircleChart/PNCircleChart.h
PNChart/PNCircleChart/PNCircleChart.m
PNChart/PNCircleChart/PNCircleChart.h
View file @
61f5cd4
...
...
@@ -8,21 +8,29 @@
#import <UIKit/UIKit.h>
#import "PNColor.h"
#import "UICountingLabel.h"
typedef
NS_ENUM
(
NSUInteger
,
PNChartFormatType
)
{
PNChartFormatTypePercent
,
PNChartFormatTypeDollar
,
PNChartFormatTypeNone
};
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
@interface
PNCircleChart
:
UIView
-
(
void
)
strokeChart
;
-
(
void
)
growChartByAmount
:(
NSNumber
*
)
growAmount
;
-
(
id
)
initWithFrame
:(
CGRect
)
frame
andTotal
:(
NSNumber
*
)
total
andCurrent
:(
NSNumber
*
)
current
andClockwise
:(
BOOL
)
clockwise
andShadow
:(
BOOL
)
hasBackgroundShadow
;
@property
(
strong
,
nonatomic
)
UICountingLabel
*
countingLabel
;
@property
(
nonatomic
)
UIColor
*
strokeColor
;
@property
(
nonatomic
)
UIColor
*
labelColor
;
@property
(
nonatomic
)
NSNumber
*
total
;
@property
(
nonatomic
)
NSNumber
*
current
;
@property
(
nonatomic
)
NSNumber
*
lineWidth
;
@property
(
nonatomic
)
BOOL
clockwise
;
@property
(
nonatomic
)
NSTimeInterval
duration
;
@property
(
nonatomic
)
PNChartFormatType
chartType
;
@property
(
nonatomic
)
CAShapeLayer
*
circle
;
@property
(
nonatomic
)
CAShapeLayer
*
circleBG
;
...
...
PNChart/PNCircleChart/PNCircleChart.m
View file @
61f5cd4
...
...
@@ -7,25 +7,12 @@
//
#import "PNCircleChart.h"
#import "UICountingLabel.h"
@interface
PNCircleChart
()
{
UICountingLabel
*
_gradeLabel
;
}
@interface
PNCircleChart
()
@end
@implementation
PNCircleChart
-
(
UIColor
*
)
labelColor
{
if
(
!
_labelColor
)
{
_labelColor
=
PNDeepGrey
;
}
return
_labelColor
;
}
-
(
id
)
initWithFrame
:(
CGRect
)
frame
andTotal
:(
NSNumber
*
)
total
andCurrent
:(
NSNumber
*
)
current
andClockwise
:(
BOOL
)
clockwise
andShadow
:(
BOOL
)
hasBackgroundShadow
{
...
...
@@ -35,7 +22,8 @@
_total
=
total
;
_current
=
current
;
_strokeColor
=
PNFreshGreen
;
_clockwise
=
clockwise
;
_duration
=
1
.
0
;
_chartType
=
PNChartFormatTypePercent
;
CGFloat
startAngle
=
clockwise
?
-
90
.
0
f
:
270
.
0
f
;
CGFloat
endAngle
=
clockwise
?
-
90
.
01
f
:
270
.
01
f
;
...
...
@@ -62,7 +50,13 @@
[
self
.
layer
addSublayer
:
_circle
];
[
self
.
layer
addSublayer
:
_circleBG
];
_gradeLabel
=
[[
UICountingLabel
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
50
.
0
,
50
.
0
)];
_countingLabel
=
[[
UICountingLabel
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
100
.
0
,
50
.
0
)];
[
_countingLabel
setTextAlignment
:
NSTextAlignmentCenter
];
[
_countingLabel
setFont
:[
UIFont
boldSystemFontOfSize
:
16
.
0
f
]];
[
_countingLabel
setTextColor
:[
UIColor
grayColor
]];
[
_countingLabel
setCenter
:
CGPointMake
(
self
.
center
.
x
,
self
.
center
.
y
)];
_countingLabel
.
method
=
UILabelCountingMethodEaseInOut
;
[
self
addSubview
:
_countingLabel
];;
}
return
self
;
...
...
@@ -71,36 +65,61 @@
-
(
void
)
strokeChart
{
//Add count label
[
_gradeLabel
setTextAlignment
:
NSTextAlignmentCenter
];
[
_gradeLabel
setFont
:[
UIFont
boldSystemFontOfSize
:
13
.
0
f
]];
[
_gradeLabel
setTextColor
:
self
.
labelColor
];
[
_gradeLabel
setCenter
:
CGPointMake
(
self
.
center
.
x
,
self
.
center
.
y
)];
_gradeLabel
.
method
=
UILabelCountingMethodEaseInOut
;
_gradeLabel
.
format
=
@"%d%%"
;
// Add counting label
NSString
*
format
;
switch
(
self
.
chartType
)
{
case
PNChartFormatTypePercent
:
format
=
@"%d%%"
;
break
;
case
PNChartFormatTypeDollar
:
format
=
@"$%d"
;
break
;
case
PNChartFormatTypeNone
:
default
:
format
=
@"%d"
;
break
;
}
self
.
countingLabel
.
format
=
format
;
[
self
addSubview
:
self
.
countingLabel
];
[
self
addSubview
:
_gradeLabel
];
//Add circle params
//
Add circle params
_circle
.
lineWidth
=
[
_lineWidth
floatValue
];
_circleBG
.
lineWidth
=
[
_lineWidth
floatValue
];
_circleBG
.
strokeEnd
=
1
.
0
;
_circle
.
strokeColor
=
_strokeColor
.
CGColor
;
//Add Animation
//
Add Animation
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
1
.
0
;
pathAnimation
.
duration
=
self
.
duration
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
pathAnimation
.
fromValue
=
@0.0f
;
pathAnimation
.
toValue
=
@
([
_current
floatValue
]
/
[
_total
floatValue
]);
[
_circle
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
_circle
.
strokeEnd
=
[
_current
floatValue
]
/
[
_total
floatValue
];
[
_
gradeLabel
countFrom
:
0
to
:[
_current
floatValue
]
/
[
_total
floatValue
]
*
100
withDuration
:
1
.
0
];
[
_
countingLabel
countFrom
:
0
to
:[
_current
floatValue
]
withDuration
:
1
.
0
];
}
-
(
void
)
growChartByAmount
:
(
NSNumber
*
)
growAmount
{
NSNumber
*
updatedValue
=
[
NSNumber
numberWithFloat
:[
_current
floatValue
]
+
[
growAmount
floatValue
]];
// Add animation
CABasicAnimation
*
pathAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"strokeEnd"
];
pathAnimation
.
duration
=
self
.
duration
;
pathAnimation
.
timingFunction
=
[
CAMediaTimingFunction
functionWithName
:
kCAMediaTimingFunctionEaseInEaseOut
];
pathAnimation
.
fromValue
=
@
([
_current
floatValue
]
/
[
_total
floatValue
]);
pathAnimation
.
toValue
=
@
([
updatedValue
floatValue
]
/
[
_total
floatValue
]);
_circle
.
strokeEnd
=
[
updatedValue
floatValue
]
/
[
_total
floatValue
];
[
_circle
addAnimation
:
pathAnimation
forKey
:
@"strokeEndAnimation"
];
[
self
.
countingLabel
countFrom
:
fmin
([
_current
floatValue
],
[
_total
floatValue
])
to
:
fmin
([
_current
floatValue
]
+
[
growAmount
floatValue
],
[
_total
floatValue
])
withDuration
:
self
.
duration
];
_current
=
updatedValue
;
}
@end
...
...
Please
register
or
login
to post a comment