I have created 3 UIView
, each one is a graphic that I used from the PNChart
library. I show them correctly all OK.
The problem comes when I want to update the value. That is, if initially the graph was in 60%
and I update it to 80%
is updated but I want to do it automatically. to verify if the value has changed and update the% with the new value.
I've tried it with addTarget
but it does not appear in the properties of PNChart
and I do not know how to do it.
UPDATED CODE AND RUNNING
import UIKit
import ALSystemUtilities
import PNChart
class CPU: UIView {
var lineChart:PNCircleChart?
override func layoutSubviews() {
lineChart = PNCircleChart(frame: CGRectMake(0 , 0, self.bounds.width, self.bounds.height) , total: 100, current: 0, clockwise: true, shadow: true, shadowColor: UIColor(red:0.94, green:0.95, blue:0.95, alpha:1.0), displayCountingLabel: true, overrideLineWidth: 13)
lineChart!.strokeColor = UIColor(red:0.42, green:0.79, blue:0.86, alpha:1.0)
self.backgroundColor = UIColor.whiteColor()
lineChart!.strokeChart()
self.addSubview(lineChart!)
// Añadimos un timer para hacer update cada x tiempo
NSTimer.scheduledTimerWithTimeInterval(3.0, target: self, selector: "updateValues", userInfo: nil, repeats: true)
}
func updateValues() {
lineChart!.updateChartByCurrent(cpu_usage())
print(cpu_usage())
}
}