1

I've created a custom marker view that loads from xib. I want to detect tap on the marker so that I can perform certain action on my VC. How can I do this?

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 is an xib that contains the Bar chart. Can Anyone provide code example on what I should do so that I can detect tap on the marker view and perform some action on VC?

da32
  • 703
  • 1
  • 9
  • 18
  • Possible duplicate of [How to detect tap gesture on chart marker?](https://stackoverflow.com/questions/51921792/how-to-detect-tap-gesture-on-chart-marker) – smandrus Dec 04 '18 at 07:31

0 Answers0