我有很多关于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); }
解决方法
您可以创建scrollView并添加图例.这是解决方法,但工作.示例代码:
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(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];
附:您应该计算图例和scrollview的坐标以及scrollview的contentSize