SwiftCharts want create a UIButton in InfoBubble

96 Views Asked by At

In my app, I use SwiftCharts lib to create some charts, like that :

demo picture

You can see in the picture , I create a BubbleInfo view when user tap the point in the chart, then I add a UIButton in BubbleInfo view, code in below:

    bubbleView.transform = CGAffineTransform(scaleX: 0, y: 0).concatenating(CGAffineTransform(translationX: 0, y: 100))

    let infoView = UILabel(frame: CGRect(x: 0, y: 10, width: w, height: h - 30))
    infoView.textColor = UIColor.white
    infoView.backgroundColor = UIColor.black
    infoView.text = "Some text about \(chartPoint)"
    infoView.font = ExamplesDefaults.fontWithSize(Env.iPad ? 14 : 12)
    infoView.textAlignment = NSTextAlignment.center

    //create button            
    let btn = UIButton(frame: infoView.bounds)
    btn.backgroundColor = UIColor.red.withAlphaComponent(0.5)
    btn.addTarget(weakSelf, action: #selector(weakSelf.btnTapped(_:)), for: .touchUpInside)

    bubbleView.addSubview(infoView)
    bubbleView.addSubview(btn)

But when I tap the button, nothing happened!

What wrong with it?
How could I fix it?
thanks ;)

0

There are 0 best solutions below