简体   繁体   中英

How To Add Scroll In CPTLegend in CorePlot

I have a lot of entries for legend.can any one please help to make the CPTLegend scrollable?

Here is the code that i am using for 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);

}

There is an outstanding feature request for this, but there's currently no built-in support for scrollable legends. You can try to make everything fit by adjusting the text and swatch size, the margins, and the number of rows and columns. The alternative is to make your own scrolling legend using a custom view and positioning it in front of the graph.

you can create scrollView and add legend. It is workaround but work. Example code:

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

PS you should calculate coordinates for legend and scrollview and contentSize for scrollview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM