2017-08-10 74 views
4

如何顯示這樣的coreplot圖例?Coreplot傳說中的標題,國家標籤,並在該行下迅速

國家標誌,根據該線(圖中的相似)

enter image description here FUNC configureLegend()國名{ 後衛讓圖形= hostView.hostedGraph其他{}回報

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 
} 

回答

0

如果您可以使用表情符號繪製標誌,做到這一點。在標題文本中插入換行符(\n)以將文本放置在標誌下。

如果您需要爲標誌使用自定義圖形,請使用圖例delegate並實施-legend:shouldDrawSwatchAtIndex:forPlot:inRect:inContext:委託方法。將標誌繪製到樣例矩形內的給定圖形上下文中,並返回NO以告訴圖例您已處理所需的繪圖。

將文本放在圖形下方,放大樣本大小並將兩者都繪製到樣本矩形中。

+0

感謝您的回覆Eric。但是,上述實現做了什麼。該線條向下移動(而不是中心),而不是在標誌和文字下 – Marios

+0

您不必使用圖例。使用Core Plot邊框圖層(標誌圖形可以是其中一個圖層的「填充」)和文本圖層來構建您想要的視圖。將此圖層層次結構作爲註釋附加到圖形上。 –