我有 OS X 应用程序的图表,可以随窗口调整大小。我预计当宽度减小得足够多时,图例将被截断或剪裁。然而,它溢出到绘图区域之外,如下所示。理想情况下,我希望图例截断或至少剪辑内容。如何做到这一点?
我的图例设置如下
- (void)configureLegend
{
// 1 - Get graph instance
CPTGraph *graph = self.graphHostingView.hostedGraph;
// 2 - Create legend
CPTLegend *theLegend;
if (!theLegend) {
theLegend = [CPTLegend legendWithGraph:graph];
}
//Configure Text
CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
textStyle.color = [CPTColor colorWithComponentRed:0.612f green:0.612f blue:0.612f alpha:1.00f];
textStyle.fontName = @"HelveticaNeue";
textStyle.fontSize = 12.0f;
theLegend.textStyle = textStyle;
// 3 - Configure legend
theLegend.numberOfColumns = 1;
theLegend.fill = nil;
theLegend.borderLineStyle = nil;
theLegend.swatchSize = CGSizeMake(10.0, 10.0);
theLegend.swatchCornerRadius = 5.0f;
// 4 - Add legend to graph
graph.legend = theLegend;
graph.legendAnchor = CPTRectAnchorLeft;
CGFloat viewWidth = self.graphHostingView.bounds.size.width;
CGFloat legendPadding = (viewWidth * 0.3) + self.pieChart.pieRadius + (viewWidth * 0.05);
graph.legendDisplacement = CGPointMake(legendPadding, 0.0);
}
最佳答案
确保图形遮盖了其子图层。使用 masksToBounds
剪裁到边框线的外部,或使用 masksToBorder
剪裁到边框的内边缘。
关于cocoa - Coreplot 图例在图框之外绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27322344/