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
dullgrass
2015-05-29 15:25:20 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
919d5aebdcdebd8d55c677ab7349711b30f17076
919d5aeb
1 parent
1cffc39c
fix bug
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
16 deletions
PNChart/PNBar.m
PNChart/PNBarChart.m
PNChartDemo/PCChartViewController.m
PNChart/PNBar.m
View file @
919d5ae
...
...
@@ -39,8 +39,8 @@
-
(
void
)
setGrade
:(
float
)
grade
{
//
NSLog(@"New garde %f",grade);
NSLog
(
@"New garde %f"
,
grade
);
_grade
=
grade
;
CGFloat
startPosY
=
(
1
-
grade
)
*
self
.
frame
.
size
.
height
;
UIBezierPath
*
progressline
=
[
UIBezierPath
bezierPath
];
...
...
@@ -180,7 +180,7 @@
_textLayer
=
[[
CATextLayer
alloc
]
init
];
[
_textLayer
setString
:
@"0"
];
[
_textLayer
setAlignmentMode
:
kCAAlignmentCenter
];
[
_textLayer
setForegroundColor
:[[
UIColor
blackColor
]
CGColor
]];
[
_textLayer
setForegroundColor
:[[
UIColor
colorWithRed
:
178
/
255
.
0
green
:
178
/
255
.
blue
:
178
/
255
.
0
alpha
:
1
.
0
]
CGColor
]];
}
return
_textLayer
;
...
...
@@ -188,23 +188,29 @@
-
(
void
)
setGradeFrame
:
(
CGFloat
)
grade
startPosY
:
(
CGFloat
)
startPosY
{
CGFloat
textheigt
=
self
.
bounds
.
size
.
width
;
CGFloat
textWidth
=
self
.
bounds
.
size
.
width
;
CGFloat
textStartPosY
;
CGFloat
textheigt
=
self
.
bounds
.
size
.
height
*
self
.
grade
;
if
(
startPosY
<
textheigt
)
{
textStartPosY
=
startPosY
;
}
else
{
textStartPosY
=
startPosY
-
textheigt
;
}
CGFloat
topSpace
=
self
.
bounds
.
size
.
height
*
(
1
-
self
.
grade
);
CGFloat
textWidth
=
self
.
bounds
.
size
.
width
;
[
_chartLine
addSublayer
:
self
.
textLayer
];
[
self
.
textLayer
setFontSize
:
textheigt
/
2
];
[
self
.
textLayer
setFontSize
:
18
.
0
];
[
self
.
textLayer
setString
:[[
NSString
alloc
]
initWithFormat
:
@"%0.f"
,
grade
*
self
.
maxDivisor
]];
[
self
.
textLayer
setFrame
:
CGRectMake
(
0
,
textStartPosY
,
textWidth
,
textheigt
)];
CGSize
size
=
CGSizeMake
(
320
,
2000
);
//设置一个行高上限
NSDictionary
*
attributes
=
@{
NSFontAttributeName
:
[
UIFont
systemFontOfSize
:
18
.
0
]};
size
=
[
self
.
textLayer
.
string
boundingRectWithSize
:
size
options
:
NSStringDrawingUsesLineFragmentOrigin
attributes
:
attributes
context
:
nil
].
size
;
float
verticalY
;
if
(
size
.
height
>=
textheigt
)
{
verticalY
=
topSpace
-
size
.
height
;
}
else
{
verticalY
=
topSpace
+
(
textheigt
-
size
.
height
)
/
2
.
0
;
}
[
self
.
textLayer
setFrame
:
CGRectMake
((
textWidth
-
size
.
width
)
/
2
.
0
,
verticalY
,
size
.
width
,
size
.
height
)];
self
.
textLayer
.
contentsScale
=
[
UIScreen
mainScreen
].
scale
;
}
...
...
@@ -212,6 +218,15 @@
-
(
void
)
setIsNegative
:
(
BOOL
)
isNegative
{
if
(
isNegative
)
{
[
self
.
textLayer
setString
:[[
NSString
alloc
]
initWithFormat
:
@"-%0.f"
,
_grade
*
self
.
maxDivisor
]];
CGSize
size
=
CGSizeMake
(
320
,
2000
);
//设置一个行高上限
NSDictionary
*
attributes
=
@{
NSFontAttributeName
:
[
UIFont
systemFontOfSize
:
18
.
0
]};
size
=
[
self
.
textLayer
.
string
boundingRectWithSize
:
size
options
:
NSStringDrawingUsesLineFragmentOrigin
attributes
:
attributes
context
:
nil
].
size
;
CGRect
frame
=
self
.
textLayer
.
frame
;
frame
.
origin
.
x
=
(
self
.
bounds
.
size
.
width
-
size
.
width
)
/
2
.
0
;
frame
.
size
=
size
;
self
.
textLayer
.
frame
=
frame
;
CABasicAnimation
*
rotationAnimation
;
rotationAnimation
=
[
CABasicAnimation
animationWithKeyPath
:
@"transform.rotation.z"
];
rotationAnimation
.
toValue
=
[
NSNumber
numberWithFloat
:
M_PI
];
...
...
PNChart/PNBarChart.m
View file @
919d5ae
PNChartDemo/PCChartViewController.m
View file @
919d5ae
...
...
@@ -113,7 +113,7 @@
[
self
.
barChart
setStrokeColors
:@[
PNGreen
,
PNGreen
,
PNRed
,
PNGreen
]];
// Adding gradient
self
.
barChart
.
barColorGradientStart
=
[
UIColor
blueColor
];
//
self.barChart.barColorGradientStart = [UIColor blueColor];
[
self
.
barChart
strokeChart
];
...
...
Please
register
or
login
to post a comment