dullgrass

delete the relationship between gradient and show numbers

... ... @@ -27,5 +27,5 @@
@property (nonatomic) CATextLayer* textLayer;
@property (nonatomic, assign) BOOL isNegative; //!< 是否是负数
@property (nonatomic, assign) BOOL isShowNumber; //!< 是否显示numbers
@end
... ...
... ... @@ -10,6 +10,12 @@
#import "PNColor.h"
#import <CoreText/CoreText.h>
@interface PNBar ()
@property (nonatomic) float copyGrade;
@end
@implementation PNBar
- (id)initWithFrame:(CGRect)frame
... ... @@ -40,7 +46,7 @@
- (void)setGrade:(float)grade
{
NSLog(@"New garde %f",grade);
_grade = grade;
_copyGrade = grade;
CGFloat startPosY = (1 - grade) * self.frame.size.height;
UIBezierPath *progressline = [UIBezierPath bezierPath];
... ... @@ -76,9 +82,7 @@
// Add gradient
[self.gradientMask addAnimation:pathAnimation forKey:@"animationKey"];
self.gradientMask.path = progressline.CGPath;
// add text
[self setGradeFrame:grade startPosY:startPosY];
CABasicAnimation* opacityAnimation = [self fadeAnimation];
[self.textLayer addAnimation:opacityAnimation forKey:nil];
... ... @@ -125,9 +129,7 @@
self.gradientMask.strokeEnd = 1.0;
[self.gradientMask addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
//set grade
[self setGradeFrame:grade startPosY:startPosY];
CABasicAnimation* opacityAnimation = [self fadeAnimation];
[self.textLayer addAnimation:opacityAnimation forKey:nil];
}
... ... @@ -181,6 +183,7 @@
[_textLayer setString:@"0"];
[_textLayer setAlignmentMode:kCAAlignmentCenter];
[_textLayer setForegroundColor:[[UIColor colorWithRed:178/255.0 green:178/255. blue:178/255.0 alpha:1.0] CGColor]];
_textLayer.hidden = YES;
}
return _textLayer;
... ... @@ -215,6 +218,14 @@
}
- (void)setIsShowNumber:(BOOL)isShowNumber{
if (isShowNumber) {
self.textLayer.hidden = NO;
[self setGradeFrame:_copyGrade startPosY:0];
}else{
self.textLayer.hidden = YES;
}
}
- (void)setIsNegative:(BOOL)isNegative{
if (isNegative) {
[self.textLayer setString:[[NSString alloc]initWithFormat:@"-%0.f",_grade*self.maxDivisor]];
... ...
... ... @@ -103,5 +103,10 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue);
@property (nonatomic, weak) id<PNChartDelegate> delegate;
/**whether show gradient bar*/
@property (nonatomic, assign) BOOL isGradientShow;
/** whether show numbers*/
@property (nonatomic, assign) BOOL isShowNumbers;
@end
... ...
... ... @@ -62,6 +62,8 @@
_showLevelLine = NO;
_yChartLabelWidth = 18;
_rotateForXAxisText = false;
_isGradientShow = YES;
_isShowNumbers = YES;
}
- (void)setYValues:(NSArray *)yValues
... ... @@ -232,9 +234,12 @@
}else{
bar.barColor = [self barColorAtIndex:index];
}
// Add gradient
bar.barColorGradientStart = bar.barColor;
if (self.isGradientShow) {
bar.barColorGradientStart = bar.barColor;
}
//For Click Index
bar.tag = index;
... ... @@ -252,6 +257,7 @@
}
bar.maxDivisor = (float)_yValueMax;
bar.grade = grade;
bar.isShowNumber = self.isShowNumbers;
CGRect originalFrame = bar.frame;
if (value<0 && self.showLevelLine) {
CGAffineTransform transform =CGAffineTransformMakeRotation(M_PI);
... ... @@ -259,7 +265,9 @@
originalFrame.origin.y = bar.frame.origin.y + bar.frame.size.height;
bar.frame = originalFrame;
bar.isNegative = YES;
}
index += 1;
}
... ...
... ... @@ -110,10 +110,9 @@
self.barChart.yValueMax=10;
self.barChart.yLabels = @[@-10,@0,@10];
[self.barChart setYValues:@[@1,@5,@(0-8),@10]];
[self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen]];
// Adding gradient
// self.barChart.barColorGradientStart = [UIColor blueColor];
self.barChart.isGradientShow = NO;
self.barChart.isShowNumbers = NO;
[self.barChart strokeChart];
... ...