我正在尝试在iPhone上去掉一个核心绘图图表周围的边框,但似乎很难在我的脑海中想象简单的事情。
请给予指导!
graph.plotAreaFrame.borderLineStyle = nil; // don't draw a border
您也可以创建自己的主题,使用框架中的主题作为示例,并在其中不设置borderLineStyle。
对我都没有用,这个方法解决了问题:
graph.paddingLeft = 0;
graph.paddingRight = 0;
graph.paddingTop = 0;
graph.paddingBottom = 0;
graph.plotAreaFrame.borderWidth = 0;
graph.plotAreaFrame.cornerRadius = 0;
好的,我找到了如何做到这一点 - 实际上非常简单!
CPLineStyle *borderLineStyle = [CPLineStyle lineStyle];
borderLineStyle.lineColor = [CPColor whiteColor];
borderLineStyle.lineWidth = 1.0;
graph.plotArea.borderLineStyle = borderLineStyle;
其中“graph”是您的图形对象 - 我之所以首先有一个边框,是因为我使用了CPPlainWhiteTheme主题。
希望这能帮助其他人 - 是否有更好的方法?
CPTGraphHostingView* hostingView = [[CPTGraphHostingView alloc] initWithFrame: frame];
CGRect bounds = hostingView.bounds;
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:bounds];
hostingView.hostedGraph = graph;
graph.paddingTop = CPTFloat(0.0);
graph.paddingRight = CPTFloat(0.0);
graph.paddingBottom = CPTFloat(0.0);
graph.paddingLeft = CPTFloat(0.0);
graph.plotAreaFrame.paddingTop = CPTFloat(0.0);
graph.plotAreaFrame.paddingRight = CPTFloat(0.0);
graph.plotAreaFrame.paddingBottom = CPTFloat(0.0);
graph.plotAreaFrame.paddingLeft = CPTFloat(0.0);
graph.plotAreaFrame.masksToBorder = NO;
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.title = nil;
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.title = nil;
CPTGraph
的结构略有改变。假设graph
是GPTGraph
类型或CPTGraph
的子类,则用于移除图形边框线的代码如下:graph.plotAreaFrame.borderLineStyle = nil;
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:hostView.bounds];
// Set padding for plot area
[graph applyTheme:[CPTTheme themeNamed:kCPTPlainWhiteTheme]];
graph.plotAreaFrame.borderLineStyle = nil;
您可以将任何线条样式设置为nil
。这将导致该线条不被绘制出来。