如何缩小CPTXYGraph和CPTGraphHostingView之间的距离?

问题描述 投票:0回答:1

[我在图形CPTXYGraph中创建了一个散点图,然后将此图形传递给CPTGraphHostingView,这是代码:

func makeGraphHostingView() -> CPTGraphHostingView {
    let hostingView = CPTGraphHostingView()

    let graph = CPTXYGraph()
    graph.axisSet!.isHidden = true
    graph.plotAreaFrame!.paddingTop = 0.0
    graph.plotAreaFrame!.paddingRight = 0.0
    graph.plotAreaFrame!.paddingBottom = 0.0
    graph.plotAreaFrame!.paddingLeft = 0.0

    hostingView.hostedGraph = graph

    let lineStyle = CPTMutableLineStyle()
    lineStyle.lineColor = CPTColor.white()
    lineStyle.lineWidth = 3.0

    let xAxisMin = 0.0
    let xAxisMax = 100.0
    let yAxisMin = 0.0
    let yAxisMax = 100.0

    let plotSpace = graph.defaultPlotSpace as! CPTXYPlotSpace
    plotSpace.xRange = CPTPlotRange(locationDecimal: Decimal(xAxisMin), lengthDecimal: Decimal(xAxisMax - xAxisMin))
    plotSpace.yRange = CPTPlotRange(locationDecimal: Decimal(yAxisMin), lengthDecimal: Decimal(yAxisMax - yAxisMin))

    let plot = CPTScatterPlot()
    plot.dataSource = self
    plot.dataLineStyle = lineStyle

    let areaFillColor = UIColor.white.withAlphaComponent(0.05)
    let fill = CPTFill(color: CPTColor(cgColor: areaFillColor.cgColor))
    plot.areaFill = fill
    plot.areaBaseValue = NSNumber(0.0)

    graph.add(plot)

    return hostingView
}

hostingView固定到具有0.0常数的Superview的前导,尾随,顶部和底部锚点(观看图片1):

enter image description here

我希望图形完全调整为与hostingView相同的范围,但是我不知道该怎么做,这里的图形填充对我没有任何帮助。有什么想法吗?

enter image description here

ios swift xcode core-animation core-plot
1个回答
0
投票

您也需要在graph上设置填充。

graph.paddingTop = 0.0
graph.paddingRight = 0.0
graph.paddingBottom = 0.0
graph.paddingLeft = 0.0
© www.soinside.com 2019 - 2024. All rights reserved.