如何在CorePlot的CPTLegend中添加滚动条

4

我有很多图例条目,有谁能帮我使 CPTLegend 可滚动?

这是我正在使用的 CPTLegend 代码。

-(void)configureLegend {
    // 1 - Get graph instance
    CPTGraph *graph = self.hostView.hostedGraph;
    // 2 - Create legend
    CPTLegend *theLegend = [CPTLegend legendWithGraph:graph];
    // 3 - Configure legen
    theLegend.numberOfColumns = 1;
    theLegend.fill = [CPTFill fillWithColor:[CPTColor clearColor]];
    theLegend.borderLineStyle = [CPTLineStyle lineStyle];
    theLegend.cornerRadius = 2.0;
    // 4 - Add legend to graph
    graph.legend = theLegend;     
    graph.legendAnchor = CPTRectAnchorBottom;
    CGFloat legendPadding = -(self.view.bounds.size.width / 3);
    graph.legendDisplacement = CGPointMake(-80, 120.0);

}
2个回答

3

您可以创建scrollView并添加图例。这是一个解决方法,但是有效。示例代码:

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1000, 450)];
scrollView.showsVerticalScrollIndicator = YES;
scrollView.clipsToBounds = YES;
scrollView.userInteractionEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.contentSize.width, 5000);
[scrollView.layer addSublayer:self.hostView.hostedGraph.legend];
[self.hostView addSubview:scrollView];

附注:您应该计算图例、滚动视图和滚动视图的内容大小的坐标。


3

目前还没有内置支持滚动图例的功能,但是有一个很棒的 功能请求。您可以通过调整文本和示例大小、边距、行数和列数来尝试让所有内容都适应屏幕。另一种选择是使用自定义视图创建自己的可滚动图例,并将其定位在图形的前面。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接