如何在Core Plot中将自定义刻度线设置为图标? [英] How to set custom tick marks in Core Plot to icons?

查看:109
本文介绍了如何在Core Plot中将自定义刻度线设置为图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让刻度线(主刻度标记)成为UIImage(自定义图形)而不是文本?
我需要在其中一个轴上显示值作为图标。
我没有看到任何代表,但也许有人知道这个伎俩?

Is there a way to make tick mark (major tick mark) to be UIImage (custom graphics) instead of text? I have values in one of the axis I need to present as icons. I do not see any delegate for this but maybe someone knows the trick?

推荐答案

轴标签可以有任何 CPTLayer (这是Core Animation的 CALayer 的直接子类)作为其内容。将图像设置为图层背景,并使用此图层构建自定义标签。一些Core Plot示例应用程序演示了自定义标签,尽管它们都使用文本标签。

Axis labels can have any CPTLayer (which is a direct subclass of Core Animation's CALayer) as its content. Set your image as the layer background and build a custom label using this layer. Several of the Core Plot example apps demonstrate custom labels, although they all use text labels.

您可以通过两种方式将自定义标签添加到图表中:

You have two options for adding your custom labels to the graph:


  1. 使用 CPTAxisLabelingPolicyNone 标签政策。创建一个包含标签的 NSSet ,并将其设置为轴上的 axisLabels 属性。如果您使用此功能,请记住除了自定义标签之外,您还必须提供主要和/或次要刻度位置。

  1. Use the CPTAxisLabelingPolicyNone labeling policy. Create a NSSet containing your labels and set it to the axisLabels property on the axis. If you use this, remember that you must provide the major and/or minor tick locations in addition to the custom labels.

使用任何其他标签政策生成tick位置并实现 -axis:shouldUpdateAxisLabelsAtLocations:轴委托方法。在您的代理人中,在提供的位置创建新标签并返回以取消自动标签。

Use any other labeling policy to generate the tick locations and implement the -axis:shouldUpdateAxisLabelsAtLocations: axis delegate method. In your delegate, create new labels at the provided locations and return NO to suppress the automatic labels.

Eric

这篇关于如何在Core Plot中将自定义刻度线设置为图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆