【问题标题】:How To Add Scroll In CPTLegend in CorePlot如何在 CorePlot 的 CPTLegend 中添加滚动
【发布时间】:2013-10-25 12:09:47
【问题描述】:

我有很多关于 Legend 的条目。谁能帮忙使 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);

}

【问题讨论】:

    标签: ios iphone objective-c core-plot


    【解决方案1】:

    您可以创建滚动视图并添加图例。这是解决方法,但工作。示例代码:

    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];
    

    附:您应该计算图例和滚动视图的坐标以及滚动视图的 contentSize

    【讨论】:

      【解决方案2】:

      为此有一个出色的feature request,但目前没有对可滚动图例的内置支持。您可以通过调整文本和样本大小、边距以及行数和列数来尝试使所有内容都适合。另一种方法是使用自定义视图制作您自己的滚动图例并将其放置在图表前面。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-07
        • 2015-03-18
        • 2011-02-19
        • 1970-01-01
        相关资源
        最近更新 更多