Showing
5 changed files
with
32 additions
and
9 deletions
| @@ -27,5 +27,5 @@ | @@ -27,5 +27,5 @@ | ||
| 27 | @property (nonatomic) CATextLayer* textLayer; | 27 | @property (nonatomic) CATextLayer* textLayer; |
| 28 | 28 | ||
| 29 | @property (nonatomic, assign) BOOL isNegative; //!< 是否是负数 | 29 | @property (nonatomic, assign) BOOL isNegative; //!< 是否是负数 |
| 30 | - | 30 | +@property (nonatomic, assign) BOOL isShowNumber; //!< 是否显示numbers |
| 31 | @end | 31 | @end |
| @@ -10,6 +10,12 @@ | @@ -10,6 +10,12 @@ | ||
| 10 | #import "PNColor.h" | 10 | #import "PNColor.h" |
| 11 | #import <CoreText/CoreText.h> | 11 | #import <CoreText/CoreText.h> |
| 12 | 12 | ||
| 13 | +@interface PNBar () | ||
| 14 | + | ||
| 15 | +@property (nonatomic) float copyGrade; | ||
| 16 | + | ||
| 17 | +@end | ||
| 18 | + | ||
| 13 | @implementation PNBar | 19 | @implementation PNBar |
| 14 | 20 | ||
| 15 | - (id)initWithFrame:(CGRect)frame | 21 | - (id)initWithFrame:(CGRect)frame |
| @@ -40,7 +46,7 @@ | @@ -40,7 +46,7 @@ | ||
| 40 | - (void)setGrade:(float)grade | 46 | - (void)setGrade:(float)grade |
| 41 | { | 47 | { |
| 42 | NSLog(@"New garde %f",grade); | 48 | NSLog(@"New garde %f",grade); |
| 43 | - _grade = grade; | 49 | + _copyGrade = grade; |
| 44 | CGFloat startPosY = (1 - grade) * self.frame.size.height; | 50 | CGFloat startPosY = (1 - grade) * self.frame.size.height; |
| 45 | 51 | ||
| 46 | UIBezierPath *progressline = [UIBezierPath bezierPath]; | 52 | UIBezierPath *progressline = [UIBezierPath bezierPath]; |
| @@ -77,8 +83,6 @@ | @@ -77,8 +83,6 @@ | ||
| 77 | [self.gradientMask addAnimation:pathAnimation forKey:@"animationKey"]; | 83 | [self.gradientMask addAnimation:pathAnimation forKey:@"animationKey"]; |
| 78 | self.gradientMask.path = progressline.CGPath; | 84 | self.gradientMask.path = progressline.CGPath; |
| 79 | 85 | ||
| 80 | - // add text | ||
| 81 | - [self setGradeFrame:grade startPosY:startPosY]; | ||
| 82 | CABasicAnimation* opacityAnimation = [self fadeAnimation]; | 86 | CABasicAnimation* opacityAnimation = [self fadeAnimation]; |
| 83 | [self.textLayer addAnimation:opacityAnimation forKey:nil]; | 87 | [self.textLayer addAnimation:opacityAnimation forKey:nil]; |
| 84 | 88 | ||
| @@ -126,8 +130,6 @@ | @@ -126,8 +130,6 @@ | ||
| 126 | self.gradientMask.strokeEnd = 1.0; | 130 | self.gradientMask.strokeEnd = 1.0; |
| 127 | [self.gradientMask addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; | 131 | [self.gradientMask addAnimation:pathAnimation forKey:@"strokeEndAnimation"]; |
| 128 | 132 | ||
| 129 | - //set grade | ||
| 130 | - [self setGradeFrame:grade startPosY:startPosY]; | ||
| 131 | CABasicAnimation* opacityAnimation = [self fadeAnimation]; | 133 | CABasicAnimation* opacityAnimation = [self fadeAnimation]; |
| 132 | [self.textLayer addAnimation:opacityAnimation forKey:nil]; | 134 | [self.textLayer addAnimation:opacityAnimation forKey:nil]; |
| 133 | } | 135 | } |
| @@ -181,6 +183,7 @@ | @@ -181,6 +183,7 @@ | ||
| 181 | [_textLayer setString:@"0"]; | 183 | [_textLayer setString:@"0"]; |
| 182 | [_textLayer setAlignmentMode:kCAAlignmentCenter]; | 184 | [_textLayer setAlignmentMode:kCAAlignmentCenter]; |
| 183 | [_textLayer setForegroundColor:[[UIColor colorWithRed:178/255.0 green:178/255. blue:178/255.0 alpha:1.0] CGColor]]; | 185 | [_textLayer setForegroundColor:[[UIColor colorWithRed:178/255.0 green:178/255. blue:178/255.0 alpha:1.0] CGColor]]; |
| 186 | + _textLayer.hidden = YES; | ||
| 184 | } | 187 | } |
| 185 | 188 | ||
| 186 | return _textLayer; | 189 | return _textLayer; |
| @@ -215,6 +218,14 @@ | @@ -215,6 +218,14 @@ | ||
| 215 | 218 | ||
| 216 | } | 219 | } |
| 217 | 220 | ||
| 221 | +- (void)setIsShowNumber:(BOOL)isShowNumber{ | ||
| 222 | + if (isShowNumber) { | ||
| 223 | + self.textLayer.hidden = NO; | ||
| 224 | + [self setGradeFrame:_copyGrade startPosY:0]; | ||
| 225 | + }else{ | ||
| 226 | + self.textLayer.hidden = YES; | ||
| 227 | + } | ||
| 228 | +} | ||
| 218 | - (void)setIsNegative:(BOOL)isNegative{ | 229 | - (void)setIsNegative:(BOOL)isNegative{ |
| 219 | if (isNegative) { | 230 | if (isNegative) { |
| 220 | [self.textLayer setString:[[NSString alloc]initWithFormat:@"-%0.f",_grade*self.maxDivisor]]; | 231 | [self.textLayer setString:[[NSString alloc]initWithFormat:@"-%0.f",_grade*self.maxDivisor]]; |
| @@ -103,5 +103,10 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); | @@ -103,5 +103,10 @@ typedef NSString *(^PNYLabelFormatter)(CGFloat yLabelValue); | ||
| 103 | 103 | ||
| 104 | @property (nonatomic, weak) id<PNChartDelegate> delegate; | 104 | @property (nonatomic, weak) id<PNChartDelegate> delegate; |
| 105 | 105 | ||
| 106 | +/**whether show gradient bar*/ | ||
| 107 | +@property (nonatomic, assign) BOOL isGradientShow; | ||
| 108 | + | ||
| 109 | +/** whether show numbers*/ | ||
| 110 | +@property (nonatomic, assign) BOOL isShowNumbers; | ||
| 106 | 111 | ||
| 107 | @end | 112 | @end |
| @@ -62,6 +62,8 @@ | @@ -62,6 +62,8 @@ | ||
| 62 | _showLevelLine = NO; | 62 | _showLevelLine = NO; |
| 63 | _yChartLabelWidth = 18; | 63 | _yChartLabelWidth = 18; |
| 64 | _rotateForXAxisText = false; | 64 | _rotateForXAxisText = false; |
| 65 | + _isGradientShow = YES; | ||
| 66 | + _isShowNumbers = YES; | ||
| 65 | } | 67 | } |
| 66 | 68 | ||
| 67 | - (void)setYValues:(NSArray *)yValues | 69 | - (void)setYValues:(NSArray *)yValues |
| @@ -232,8 +234,11 @@ | @@ -232,8 +234,11 @@ | ||
| 232 | }else{ | 234 | }else{ |
| 233 | bar.barColor = [self barColorAtIndex:index]; | 235 | bar.barColor = [self barColorAtIndex:index]; |
| 234 | } | 236 | } |
| 237 | + | ||
| 235 | // Add gradient | 238 | // Add gradient |
| 239 | + if (self.isGradientShow) { | ||
| 236 | bar.barColorGradientStart = bar.barColor; | 240 | bar.barColorGradientStart = bar.barColor; |
| 241 | + } | ||
| 237 | 242 | ||
| 238 | //For Click Index | 243 | //For Click Index |
| 239 | bar.tag = index; | 244 | bar.tag = index; |
| @@ -252,6 +257,7 @@ | @@ -252,6 +257,7 @@ | ||
| 252 | } | 257 | } |
| 253 | bar.maxDivisor = (float)_yValueMax; | 258 | bar.maxDivisor = (float)_yValueMax; |
| 254 | bar.grade = grade; | 259 | bar.grade = grade; |
| 260 | + bar.isShowNumber = self.isShowNumbers; | ||
| 255 | CGRect originalFrame = bar.frame; | 261 | CGRect originalFrame = bar.frame; |
| 256 | if (value<0 && self.showLevelLine) { | 262 | if (value<0 && self.showLevelLine) { |
| 257 | CGAffineTransform transform =CGAffineTransformMakeRotation(M_PI); | 263 | CGAffineTransform transform =CGAffineTransformMakeRotation(M_PI); |
| @@ -259,7 +265,9 @@ | @@ -259,7 +265,9 @@ | ||
| 259 | 265 | ||
| 260 | originalFrame.origin.y = bar.frame.origin.y + bar.frame.size.height; | 266 | originalFrame.origin.y = bar.frame.origin.y + bar.frame.size.height; |
| 261 | bar.frame = originalFrame; | 267 | bar.frame = originalFrame; |
| 268 | + | ||
| 262 | bar.isNegative = YES; | 269 | bar.isNegative = YES; |
| 270 | + | ||
| 263 | } | 271 | } |
| 264 | index += 1; | 272 | index += 1; |
| 265 | } | 273 | } |
| @@ -110,10 +110,9 @@ | @@ -110,10 +110,9 @@ | ||
| 110 | self.barChart.yValueMax=10; | 110 | self.barChart.yValueMax=10; |
| 111 | self.barChart.yLabels = @[@-10,@0,@10]; | 111 | self.barChart.yLabels = @[@-10,@0,@10]; |
| 112 | [self.barChart setYValues:@[@1,@5,@(0-8),@10]]; | 112 | [self.barChart setYValues:@[@1,@5,@(0-8),@10]]; |
| 113 | - | ||
| 114 | [self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen]]; | 113 | [self.barChart setStrokeColors:@[PNGreen,PNGreen,PNRed,PNGreen]]; |
| 115 | - // Adding gradient | 114 | + self.barChart.isGradientShow = NO; |
| 116 | -// self.barChart.barColorGradientStart = [UIColor blueColor]; | 115 | + self.barChart.isShowNumbers = NO; |
| 117 | 116 | ||
| 118 | [self.barChart strokeChart]; | 117 | [self.barChart strokeChart]; |
| 119 | 118 |
-
Please register or login to post a comment