我有很多图例条目,任何人都可以帮助使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);
}
您可以创建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];
附言您应该计算图例和滚动视图的坐标以及滚动视图的内容大小
对此有一个
未完成的功能请求,但目前没有对可滚动图例的内置支持。您可以尝试通过调整文本和色板大小、边距以及行数和列数来使所有内容适合。另一种方法是使用自定义视图制作自己的滚动图例并将其放置在图形前面。