dullgrass

fix bug

... ... @@ -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 textheigt = self.bounds.size.height*self.grade;
CGFloat topSpace = self.bounds.size.height * (1-self.grade);
CGFloat textWidth = self.bounds.size.width;
CGFloat textStartPosY;
if (startPosY < textheigt) {
textStartPosY = startPosY;
}
else {
textStartPosY = startPosY - textheigt;
}
[_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];
... ...
... ... @@ -250,7 +250,7 @@
if (isnan(grade)) {
grade = 0;
}
bar.maxDivisor = (float)_yValueMax;
bar.maxDivisor = (float)_yValueMax;
bar.grade = grade;
CGRect originalFrame = bar.frame;
if (value<0 && self.showLevelLine) {
... ...
... ... @@ -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];
... ...