使用iOS图表在自定义标记视图上点击手势

时间:2018-11-29 08:20:08

标签: ios ios-charts

我创建了一个自定义标记视图,该视图从xib加载。我想检测标记上的敲击,以便可以在VC上执行某些操作。我该怎么办?

PerformanceHomeViewController:

@IBOutlet weak var segmentBarChartView: SegmentBarChartView!

override func viewDidLoad() {
    super.viewDidLoad()

    self.segmentBarChartView.setupMarkerView(customText: "%@ of 30 Agents")

}

SegmentBarChartView.swift

func setupMarkerView(customText: String) {
    let customMarker: CustomMarker = (CustomMarker.viewFromXib() as? CustomMarker)!
    customMarker.backgroundColor = .black
    customMarker.setup(font: AIAMetrics.barChartTitleFont, textColor: .white, customString: customText)
    customMarker.chartView = chartView

    chartView.marker = customMarker
}

CustomMarkerView

@IBOutlet weak var textLabel: UILabel!
open var font: UIFont = .systemFont(ofSize: 12)
open var textColor: UIColor = .white
open var customString: String = ""

override open func awakeFromNib() {
    self.offset.x = -self.frame.size.width / 2.0
    self.offset.y = -self.frame.size.height - 7.0
}

public func setup(font: UIFont, textColor: UIColor, customString: String)
{
    self.font = font
    self.textColor = textColor
    self.customString = customString
}

open override func refreshContent(entry: ChartDataEntry, highlight: Highlight) {
    let labelString = String(format: customString, String(format: "%.0f", entry.y))

    textLabel.text = labelString
    layoutIfNeeded()
    setLabel(labelString)
    layoutIfNeeded()
}

open func setLabel(_ newLabel: String)
{
    var size = CGSize()
    size.width = textLabel.frame.size.width + 25 + 27
    size.height = textLabel.frame.size.height + 20
    size.height = max(size.height, 52)
    self.frame.size = size
}

SegmentBarChartView是一个包含条形图的xib。 任何人都可以提供我应该怎么做的代码示例,以便我可以检测到标记视图上的敲击并在VC上执行一些操作吗?

0 个答案:

没有答案