ios - 如何在 Core Plot 中使用多个自定义标签?

标签 ios xcode core-plot

我遇到了核心情节的问题,这让我很伤心,并且搜索了互联网也找不到解决方案。我担心这是一个非常简单的疏忽,但就我的生活而言,我无法弄清楚它是什么。

基本上,当我在核心图中设置自定义标签时,只有一个标 checkout 现在刻度位置零处,即使相关数组填充了正确的数据,如刻度位置和标签。

我通过在 customLabels 数组中手动​​输入 newLabels 来绕过自定义标签例程,这很有效,所以我担心我在例程中遗漏了一些基本的东西。

NSUInteger labelLocation = 0;
NSMutableArray *customLabels = [[NSMutableArray alloc] initWithCapacity:[self.days count]];


for (NSNumber *tickLocation in self.customTickLocations)
{

    CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[self.dateLabels objectAtIndex:labelLocation] textStyle:axisTextStyle];
newLabel.tickLocation = [tickLocation decimalValue];
    int i = [tickLocation intValue];

    newLabel.offset = 5.0f;
    newLabel.rotation = M_PI/4;

    [customLabels addObject:newLabel];
    NSLog(@"Label is %@", [self.dateLabels objectAtIndex:labelLocation]);

    labelLocation = labelLocation + 1;


    NSLog(@"Tick Location is %i", i);
}
NSLog(@"Number of labels is %i", [customLabels count]);

axisSet.xAxis.axisLabels = [NSSet setWithArray:customLabels];
axisSet.xAxis.majorTickLocations = [NSSet setWithArray:self.customTickLocations];

NSLog(@"I have set customlabels");

这是我的日志:

2012-09-11 10:39:23.725 SnoozeBaby[12000:c07] Label is 11 Sep

2012-09-11 10:39:23.725 SnoozeBaby[12000:c07] Tick Location is 0

2012-09-11 10:39:23.725 SnoozeBaby[12000:c07] Label is 10 Sep

2012-09-11 10:39:23.726 SnoozeBaby[12000:c07] Tick Location is 150

2012-09-11 10:39:23.726 SnoozeBaby[12000:c07] Number of labels is 2

2012-09-11 10:39:23.728 SnoozeBaby[12000:c07] I have set customlabels

最佳答案

您是否将 CPTAxis 标签策略设置为 CPTAxisLabelingPolicyNone?除非您这样做,否则您将无法看到标签。

要注意的第二件事是,您不会释放每次迭代创建的每个 CPTAxisLabel 对象。

我还没有测试过这个,但我会说你应该先设置位置,然后再设置标签:

axisSet.xAxis.majorTickLocations = [NSSet setWithArray:self.customTickLocations];
axisSet.xAxis.axisLabels = [NSSet setWithArray:customLabels];

关于ios - 如何在 Core Plot 中使用多个自定义标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12367268/

相关文章:

iphone - 具有左右 Y 轴的核心图

iOS Autolayout 调整标签大小和它们之间的空间

ios - 无法使用应用商店分发配置文件安装 iPhone 应用

ios - 寻找给定 MKMapItems 的最小边界区域

ios - 带顶部对齐的 Watchkit 多行标签

ios - 黑色正方形边框出现在核心图饼图中

iphone - 核心图 Objective-C,即使使用 [graph.defaultPlotSpace scaleToFitPlots :[graph allPlots]]],具有单图的图也不会自动缩放

ios - 使用非公共(public) API MPMoviePlayerContenPreloadDidFinishNotification 拒绝提交

没有错误或堆栈跟踪的 iOS 崩溃

swift - xcode 想要 ""而不是 ""