kevinzhow / PNChart

A simple and beautiful chart lib used in Piner and CoinsMan for iOS
MIT License
9.71k stars 1.76k forks source link

pncircle chart won't increment? #351

Open toy5429274 opened 7 years ago

toy5429274 commented 7 years ago

I would like to increment the a value for pncircle chart by 1 when a button is click. But somehow the UI won't get updated. Please help

screen shot 2559-12-15 at 10 23 46 am

`import UIKit import PNChart

class ViewController: UIViewController {

//global var
let number = NSNumber(value: 15)

//obj outlet
@IBOutlet weak var circleChart: PNCircleChart!

override func viewDidLoad() {
    super.viewDidLoad()
}

override func viewWillAppear(_ animated: Bool) {

    let myCgrect = CGRect(x: self.view.bounds.width/2 - 40, y: self.view.bounds.height/2 - 40, width: 100, height: 100)

    let circleChart = PNCircleChart(frame: myCgrect , total: Int(100) as NSNumber!, current:  number , clockwise: false, shadow: false, shadowColor: UIColor.red)

        circleChart?.backgroundColor = UIColor.clear
        circleChart?.strokeColor = UIColor.blue
        circleChart?.stroke()

    self.view.addSubview(circleChart!)

}

@IBAction func increaseCircle(_ sender: Any) {

    _ = NSNumber(value: number.intValue + 1)
    print("btnpressed")
}

}// end uiviewcontroller `

bhushanb02 commented 7 years ago

Use - (void)updateChartByCurrent:(NSNumber *)current; method to increase PNCircleChart's current value. From your code, in increaseCircle function, you only initialise NSNumber. Assign that NSNumber to your number variable and pass it to updateChartByCurrent method.