我在回答了你的问题在我们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标准,但该帖子上的大多数用户都同意代码建议在那里工作。 (您可能希望添加更多的观察员,而不是我在此处添加的内容。)
对于相当长的解决方法,我表示歉意,但希望它对您有所帮助。
谢谢。你知道新版本什么时候发布吗? –
不幸的是,我们还没有此问题的发布日期。 – alison