2017-06-19 82 views
0

我想創建帶有一點定製輻條的餅圖。Shinobi iOS:餅圖與價值和名稱輻射

我想實現的是顯示名稱od數據點以上的輻條和價值低於發言。現在我知道如何與線

func sChart(_ chart: ShinobiChart, labelForSliceAt sliceIndex: Int, in series: SChartRadialSeries) -> UILabel? 

,並設置標籤號做兩個以上2 .... enter image description here

如何把下面的一個標籤及以上嗎?

馬克

回答

1

我在回答了你的問題在我們shinobicontrols forum,但我在這裏貼上我的答案的情況下,任何人都遇到這個帖子:

如果你沒有使用輻條,然後順便做這將是使用委託方法sChart:alterLabel:forDatapoint:atSliceIndex:inRadialSeries:重新定位標籤,但不幸的是,目前存在一個問題,這意味着在顯示輻條時,在標籤定位之前調用此方法。

我們會嘗試通過創建自己的附加標籤和使用國際志願者組織,這樣得到固定爲未來的shinobicharts但在此期間,你可以解決此問題釋放問題:

func sChart(_ chart: ShinobiChart, labelForSliceAt sliceIndex: Int, in series: SChartRadialSeries) -> UILabel { 
    let pieSeries = series as! SChartPieSeries 
    let dp = self.sChart(chart, dataPointAt: sliceIndex, forSeriesAt: 0) 
    let label = UILabel() 
    label.text = String(format:"Slice %i", sliceIndex) 
    label.sizeToFit() 
    label.addObserver(self, forKeyPath: "frame", options: NSKeyValueObservingOptions(rawValue: 0), context: nil) 
    label.addObserver(self, forKeyPath: "center", options: NSKeyValueObservingOptions(rawValue: 0), context: nil) 
    label.layer.addObserver(self, forKeyPath: "frame", options: NSKeyValueObservingOptions(rawValue: 0), context: nil) 
    label.layer.addObserver(self, forKeyPath: "center", options: NSKeyValueObservingOptions(rawValue: 0), context: nil) 

    sliceLabels[sliceIndex] = label 

    let customLabel = UILabel() 
    customLabel.text = String(format:"Value: %.0f", dp.sChartYValue() as! Float) 
    customLabel.font = pieSeries.style().labelFont 
    customLabel.textColor = pieSeries.style().labelFontColor 
    customLabel.backgroundColor = pieSeries.style().labelBackgroundColor 
    customLabel.sizeToFit() 
    chart.canvas.overlay.addSubview(customLabel); 
    customLabels[sliceIndex] = customLabel; 

    return label; 
} 

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { 
    if let changedLabel = object as? UILabel { 
     for (index, label) in sliceLabels { 
      if let sliceLabel = label as? UILabel, sliceLabel === changedLabel { 
       let customLabel = customLabels[index] as! UILabel 
       customLabel.center = CGPoint(x: sliceLabel.center.x, 
              y: sliceLabel.center.y + sliceLabel.frame.size.height); 
      } 
     } 
    } 
} 

請注意,正如解釋here UIKit不符合正式的KVO標準,但該帖子上的大多數用戶都同意代碼建議在那裏工作。 (您可能希望添加更多的觀察員,而不是我在此處添加的內容。)

對於相當長的解決方法,我表示歉意,但希望它對您有所幫助。

+0

謝謝。你知道新版本什麼時候發佈嗎? –

+0

不幸的是,我們還沒有此問題的發佈日期。 – alison