带有标题,国家标签的Coreplot图例以及swift中的该行

时间:2017-08-10 13:26:17

标签: ios iphone swift xcode core-plot

如何像这样显示coreplot图例?

国家/地区标志,该行下的国家/地区名称(类似于图表)

enter image description here func configureLegend(){         guard let graph = hostView.hostedGraph else {return}

    let legend = CPTLegend(graph: graph)
    graph.legend = legend
    graph.legendAnchor = .topLeft
    graph.legendDisplacement = CGPoint(x: 50.0, y: -2.0)
    legend.fill = CPTFill(color: CPTColor.clear())
    legend.swatchSize = CGSize(width: 10.0, height: 10.0)
    legend.numberOfRows = 1
    legend.entryPaddingBottom = 12
    let titleStyle = CPTMutableTextStyle()
    titleStyle.color = CPTColor.black()
    titleStyle.fontSize = 6.0
    titleStyle.fontName = Font.NissanPro_Bold
    legend.textStyle = titleStyle
    legend.delegate = self
}
public func legend(_ legend: CPTLegend, shouldDrawSwatchAt idx: UInt, for plot: CPTPlot, in rect: CGRect, in context: CGContext) -> Bool{
    return false
}

1 个答案:

答案 0 :(得分:0)

如果您可以使用表情符号绘制标记,请执行此操作。在标题文本中插入换行符(\n)以将文本放置在标记下。

如果您需要为标志使用自定义图形,请使用图例delegate并实施-legend:shouldDrawSwatchAtIndex:forPlot:inRect:inContext:委托方法。将标记绘制到样本矩形内的给定图形上下文中,并返回NO以告诉图例您已处理所需的图形。

要将文字放在图形下方,请放大色板尺寸并将两者绘制到色板矩形中。