2013-10-25 36 views
4

我有很多legend.can的條目請幫助使CPTLegend滾動嗎?如何在CorePlot的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); 

} 

回答

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

P.S.你應該爲圖例計算座標,scrollview和contentSize用於滾動視圖

3

有這個出色的feature request,但目前尚無內置的滾動傳說支持。您可以嘗試通過調整文本和樣本大小,邊距以及行和列的數量來使所有內容都適合。另一種方法是使用自定義視圖製作自己的滾動圖例並將其放置在圖形前面。