![](/img/trans.png)
[英]Is UILabel the best way to display a simple vertical bar graph in iOS?
[英]ios simple bar graph with animation
我需要在我的应用程序中显示2个条形图,我不想使用核心情节,因为过度杀伤只显示2个变量高度的条形图,[UIimageView with box.png]
我只是使用UIView动画完成了一些测试,这似乎足以使条形成长或缩小,[问题是高度取决于起点,所以我的条形对Y没有0点,哪里有变化与酒吧的高度]
那我怎么能为我的Y轴设置一个0点?所以我只需要考虑高度,而不是起点?
或者我应该使用一些不像核心情节那样过度杀死的条形发生器框架,
什么是最简单,最轻的重量?
ecgraph ,其他?
PS。 另一点是,我需要有一个自定义的图表背景,自定义栏,这就是为什么我使用box.png为条]
编码...
viewDidLoad { ***
CGRect chartbackGroundImageRect = CGRectMake(150, 20, 632, 653);
UIImageView *chartbackGroundImage = [[UIImageView alloc] initWithFrame:chartbackGroundImageRect];
[chartbackGroundImage setImage:[UIImage imageNamed:@"chartArtBgnd.png"]];
chartbackGroundImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:chartbackGroundImage];
[chartbackGroundImage release];
CGRect leftBarImageRect = CGRectMake(550, 550, 81, 40);
leftBarImage = [[UIImageView alloc] initWithFrame:leftBarImageRect];
[leftBarImage setImage:[UIImage imageNamed:@"leftBar.png"]];
leftBarImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:leftBarImage];
[leftBarImage release];
***}
testBarAnimation {***
// Setup the animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2]; //animation for arrow
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationBeginsFromCurrentState:YES];
CGRect newFrame = CGRectMake(550, 300, 81, 290);
leftBarImage.frame = newFrame;
[UIView commitAnimations];
***}
非常感谢!
我不知道,它适用于您的项目。 但是我使用了不同的方法,因为iOS没有适合Chart的好库。
我使用UIWebview与Web上提供的基于HTML5 / CSS的免费图表引擎。 对我来说它的工作正常,比本机图表慢一点对我的项目来说足够了
定义效用函数:
CGRect modifyRectByHeight(CGRect originalRect, CGFloat newHeight)
{
CGRect result = originalRect;
result.origin.y += height;
result.size.height += height;
return result;
}
然后使用如下:
leftBarImage.frame = modifyRectByHeight( leftBarImage.frame, 150);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.