如何使用某些图形在xcode中显示车辆的RPM
问题描述:
我是xcode的新手。这是我第一个应用程序。在这个应用程序中,我需要显示车辆的RPM,并从JSON
服务获取RPM数据。但我不知道如何使用图形来显示它。请建议我解决这个问题。提前致谢。如何使用某些图形在xcode中显示车辆的RPM
答
您想将RPM显示为条形图吗?你可以为此使用UIView。
_graph = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 20)];
[_graph setBackgroundColor:[UIColor redColor]];
[self.view addSubview:_graph];
和RPM设置方法:
- (void)setRPM:(NSInteger)rpm
{
const NSInteger maxRPM = 2000;
const NSInteger maxWidth = 200;
[UIView animateWithDuration:0.5
animations:^{
CGRect frame = _graph.frame;
frame.size.width = maxWidth * (rpm/maxRPM);
_graph.frame = frame;
}];
}
现在,你可以改变大小吧...
[self setRPM:1000]
这个怎么样?
什么是RPM?请更清楚 –
@BogdanSomlea RPM表示每分钟旋转速度计算器 – iBeginner
,您想如何以图形方式显示它? –