I am trying to create a simple bar chart from a UIImageView, the code I have s开发者_运维技巧o far is:
- (void)createNewBarWithValue:(float)percent andImage:(UIImageView *)newBar
{
CABasicAnimation *scaleToValue = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
scaleToValue.toValue = [NSNumber numberWithFloat:percent*2.5];
scaleToValue.fromValue = [NSNumber numberWithFloat:0];
scaleToValue.duration = 1.5f;
scaleToValue.delegate = self;
newBar.layer.anchorPoint = CGPointMake(0.5, 1);
[newBar.layer addAnimation:scaleToValue forKey:@"scaleUp"];
CGAffineTransform scaleTo = CGAffineTransformMakeScale( 1.0f, percent * 2.5);
newBar.transform = scaleTo;
}
All I am doing here is really simple just using transformation to get an animation. The result of the animation can be seen here.
Now what I want to do is actually to have my final chart like this:
Now one issue that I see here now is the cornered border on top. I can't do this with what I currently have. So what is the most easiest fix to do this?
Try this:
newBar.layer.cornerRadius = 5;//or any other value
Unfortunately, this will set the radius of all four corners. You might have to hide the bottom two corners and adjust the height accordingly or add another image view on top of the bottom portion of newBar
.
精彩评论