如何正确地将 Core Plot 标签/注释添加到 CPPieChart 对象?
我正在测试 CPPieChart
并发现数据源委托方法 -sliceLabelForPieChart:recordIndex:
未显示切片标签。
此外,饼图类型没有 title
属性。
所以我想我应该使用 UILabel
实例进行测试:
UILabel *viewTitle = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 24.0f)];
viewTitle.text = @"Total Space";
[hostingView addSubview:viewTitle];
[viewTitle release];
有趣的是,它看起来标签坐标被反转并且文本被镜像:
解决坐标系反转和文本镜像的最佳方法是什么?
I am testing a CPPieChart
and finding that the data source delegate method -sliceLabelForPieChart:recordIndex:
is not displaying a slice label.
In addition, there is no title
property for the pie chart type.
So I figured I would test using a UILabel
instance:
UILabel *viewTitle = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 24.0f)];
viewTitle.text = @"Total Space";
[hostingView addSubview:viewTitle];
[viewTitle release];
Interestingly, it looks like the label coordinates are inverted and the text is mirrored:
What is the best way to resolve the coordinate system inversion and text mirroring?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对此感到抱歉。在某个时候,我需要完成该图表类型的实现。
UILabel 被翻转的原因是我们将 Core Plot 图形托管在 UIView 中,该 UIView 反转了其图层的坐标系。这样做是为了在框架中保留 Mac 和 iPhone 之间相同的坐标系(基于正常的 Quartz 坐标系,其中 0,0 是左下角)。
您可以直接将 CPTextLayer 添加到图形层(或显示层次结构中的其他层之一),而不是向图形添加 UILabel。 CPTextLayers 在 Core Plot 图形的标准坐标空间内运行,因此它们应该正确渲染。
Sorry about that. At some point, I need to finish the implementation of that chart type.
The reason the UILabel is being flipped is that we host the Core Plot graphs within a UIView that inverts its layer's coordinate system. This is done to preserve the same coordinate system between Mac and iPhone for the framework (based on the normal Quartz coordinate system where 0,0 is the bottom left).
Instead of adding a UILabel to the graph, you could directly add a CPTextLayer to the graph layer (or one of the other layers in the display hierarchy). CPTextLayers play within the standard coordinate space of the Core Plot graphs, so they should render properly.
切片标签尚未实现——存在用于定义接口的委托方法,但尚未使用。
我们最近添加了向图表添加标题的功能,但不添加单个图。
iPhone 版本的 CPTestApp 在条形图中添加了一个标题以显示其完成情况。
Slice labels are not implemented--that delegate method exists to define the interface, but is not used yet.
We recently added the ability to add titles to the graph but not individual plots.
The iPhone version of CPTestApp adds a title to the bar chart to show how it's done.