我有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);
}
答案 0 :(得分:1)
确保图形屏蔽其子图层。使用masksToBounds
剪贴到边框线的外侧或masksToBorder
剪辑到边框的内边缘。